什么是 .apply jQuery 函数? [英] What's the .apply jQuery function?
问题描述
我在不同的插件和代码中看到了这一点,但我不明白那个功能是什么......在 jQuery api 中没有被引用!
I see that in different plugins and codes, but I don't understand what does that function... In the jQuery api isn't referenced!
推荐答案
apply
调用带有一组参数的函数.它不是 jQuery 的一部分,而是核心 Javascript 的一部分.但是,在 jQuery 文档中提到了它:
apply
calls a function with a set of arguments. It's not part of jQuery, it's part of core Javascript. However, there is mention of it in the jQuery docs:
http://docs.jquery.com/Types#Context.2C_Call_and_Apply
语法:
somefunction.apply(thisObj, [argsArray])
上面调用函数somefunction
,在函数作用域内将this
设置为thisObj
,并传入argsArray中的参数
作为函数的参数.
The above calls the function somefunction
, setting this
to thisObj
within the function's scope, and passing in the arguments from argsArray
as the arguments to the function.
这篇关于什么是 .apply jQuery 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!