什么是.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
,将此
设置为 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屋!