gpt4 book ai didi

jquery - 在jquery中设置this的值

转载 作者:行者123 更新时间:2023-12-01 04:28:39 25 4
gpt4 key购买 nike

在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com