var obj = { name: "I am the name of obj", sayName: function () { alert(this.name); } } $("#guoBtn").click(obj.sayName); //I am the name of the button // What if I want to access obj’s name? $("#guoBtn").click($.proxy(obj.sayName,obj));//"I am obj’s name" $("#guoBtn").click($.proxy(obj, "sayName")); //"I am obj's name"
From above proxy(a,b ) can be seen that there are two ways to write its parameters.
The first way: a is a function function, and b is the object owner of this function.
The second way: a is an object, b is a string, and is the attribute name of a.
The panel will disappear only after clicking the button.
Personally, I feel that proxy is mainly used to modify the context object when the function is executed. .
is encapsulated on the basis of apply, so proxy is our jQuery’s own apply.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn