Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the types of JavaScript proxy patterns

Shulou Source: shulou.com Published: 2022-06-03 10:06:00 10月05日 Update

Editor to share with you what are the types of JavaScript agent model, I hope you will gain something after reading this article, let's discuss it together!

1. The types of agents mainly include protection agents and virtual agents. Protection agents are used to control the access of different permission objects to the target object.

2. Virtual agents postpone high-cost objects until they are really needed.

Virtual agents are more commonly used in Javascript.

Example

Var myImage = (function () {var imgNode = document.createElement ('img'); document.body.appendChild (imgNode); return {setSrc: function (src) {imgNode.src = src;}) (); var proxyImage = (function () {var img = new Image; img.onload = function () {myImage.setSrc (this.src) } return {setSrc: function (src) {myImage.setSrc ('. / loading.gif'); img.src = src;}) (); proxyImage.setSrc ('http://xxxxx.jpg'); After reading this article, I believe you have a certain understanding of "what are the types of JavaScript agent models". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Agents types objects patterns articles protection differences dead examples commonly used cost time more permissions goals knowledge industry information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Linux Huawei Docker macOS