匿名函数参数及其传递顺序

Anonymous function arguments and the order they are passed

解释:

我无法理解匿名函数的是他们的论点。

假设我们正在使用 jQuery.each();

我知道如果我们调用 each() 并使用我所说的 anonymous callback function

$.each('p', function(index, item){

我可以 'grab' 使用匿名函数的索引和元素,如上所示。使用它我可以做类似

的事情
var array = [];

$.each('p', function(index, item){
    if(index % 3 === 0) array.push(item);
});

使用匿名函数我抓取了当前元素的索引,它是 运行 each 反对然后 push-ed 到一个数组 if 我可以将 index 除以三,或者基本上每 3 项。

问题:

所有的方法都是通过匿名函数为我们抛出不同的参数给'catch',还是它们都遵循(index, element, etc.)

的严格模式

如果它们都不同,有没有办法找出从方法传递的数据?

不,您不能指望论点总是相同的,因为有意义的内容在很大程度上取决于上下文。

有一种非常简单的方法可以找出将给出的参数:read the documentation :)

例如,the documentation for .each() 读取

.each( function ) Returns: jQuery
Description: Iterate over a jQuery object, executing a function for each matched element.

function
Type: Function( Integer index, Element element )
A function to execute for each matched element.