This is a parameter. An argument will be passed to it. I imagine that even though I do not know the correct terminology, I know what a parameter is for.
In this case, the e
will receive arguments sent by the each()
function. This function is intended to scan a collection of data. Then each member of this collection will call the anonymous function written there and the collection element (in this case, the index it will be sent as an argument.
I am actually describing what I know of this function. Functions that call anonymous functions should document how the anonymous function (what you wrote) should be written, what parameters it should receive, in general what it should do and what it should return.
And of course you can write a function of your that receives an anonymous function as an argument. If you do this, you have to document how it will be used.
Let's see the source of the each()
function:
function (obj, callback) {
var length, i = 0;
if (isArrayLike(obj)) {
length = obj.length;
for (; i < length; i++) {
if (callback.call(obj[i], i, obj[i]) === false) {
break;
}
}
} else {
for (i in obj) {
if (callback.call(obj[i], i, obj[i]) === false) {
break;
}
}
}
return obj;
}
The callback.call
makes the call to their function. The parameters of this function are:
-
thisArg
- which is the element
-
arg1
and arg2
- which is the index and again the element
The arg1
is actually passed as an argument to your anonymous function. In case it is expressed by the variable i
in the loop.
If your function declares the parameters as (i, e)
you can receive the index and the element being parsed in that iteration. In some situations just receive the index, in others also need to know the exact element.
A final addendum: almost always a common loop solves as well or better than using the each()
function.