开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜