proxy Implementation Binding Proxy Method of JQuery
- 2021-07-06 09:56:40
- OfStack
In javascript, the object referred to by this will change from time to time, which will cause program confusion. One common practice is to save this in a variable first, so we are not afraid of her change. Let's look at a small example first
var A = function(){
this.star = functiont(){};
this.beg = function(){
var that = this;
$node.click(function(){
//this.start();// Here's this Refers to the $node Object
that.start();
});
};
}
JQuery provides proxy method, which can bind a proxy object, this has changed, I am not afraid, that when this, I am not afraid, proxy has you, the object changes, I am not afraid......
$node.on('click',$.proxy(function(){
this.start();
},this)