在Mootools中,可以控制函数内this变量的值:
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
这可以在 Jquery 中完成吗?
最佳答案
jQuery 提供了.proxy()
方法。它基本上与 .apply()
或 .call()
相同,其语法如下:
$.proxy(method, scope);
在您的示例中,它将是:
var bar = $.proxy(foo, some_object);
引用号:.proxy()
关于jquery - 在jquery中设置this的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4364842/