Set value of this in jquery
In Mootools, the value of the thi开发者_运维技巧s variable within a function can be controlled:
function foo() { // do something with the this variable } var bar = foo.bind(some_object); // Now bar does the same thing as foo, except // the this variable is a reference to some_object
Can this be done in Jquery?
jQuery offers the .proxy()
method. It basically does the same as .apply()
or .call()
and it's syntax looks like:
$.proxy(method, scope);
In your example it would be:
var bar = $.proxy(foo, some_object);
Ref.: .proxy()
精彩评论