This is a parameter. An argument will be passed for him. I imagine that even not knowing the correct terminology, know what serves a parameter.
In this case the e
will receive arguments sent by the function each()
. This function aims to scan a data collection. Then each member of this collection will trigger a call to anonymous function written there and the collection element (in this case, its index) will be sent as argument.
I’m actually describing what I know about this function. Functions that call anonymous functions should document as well as the anonymous function (that you wrote) should be written, what parameters it should receive, in general lines what it should do and what it should return.
And of course you can write a function of your own 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 function each()
:
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;
}
I put in the Github for future reference.
The callback.call
is calling its 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 that it will actually be passed as argument to its anonymous function. In the 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 analyzed 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 loop common solves as well or better than the use of the function each()
.
The
e
was normally used for events, orevent
. But it generalized and everyone started usinge
, without really understanding why. But you don’t necessarily need to calle
.– DontVoteMeDown