each() method in jQuery contains such a statement:
callback.call( value, i, value )
I couldn’t understand what this statement means exactly.
I know what callback and call mean but I couldn’t get the arguments of the function call: (value,i,value). What does this mean?
The statement is used in a for block of each() but my question is independent of that context.
from the jQuery source:
for ( var value = object[0];
i < length &&
callback.call( value, i, value ) // <=== LOOK!
!== false;
value = object[++i] ) {}
The
callmethod exists on all functions in Javascript. It allows you to call the function and in doing so set the value ofthiswithin that function.In this example,
thiswithinmyFuncwill bedocument.body.The first parameter of
callis the value to be set asthis; subsequent parameters are passed on to the function as normal parameters. So, in your example:this is equivalent to
except that, within the callback,
thisis now also set tovalue.