开发者

Set value of this in jquery

开发者 https://www.devze.com 2023-01-28 08:24 出处:网络
In Mootools, the value of the thi开发者_运维技巧s variable within a function can be controlled:

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()

0

精彩评论

暂无评论...
验证码 换一张
取 消