How argument is being passed in the function(which itself is an argument) in JavaScript -
i have basic question javascript. consider next code:
var numbers = [4,2,3,4,5,4,3,2,1]; var everyresult = numbers.every(function(item,index,array) { alert(arguments.length); homecoming (item > 1); });
now in above code passing anonymous function argument of "every" function. how anonymous function getting 3 arguments(item,index,array).
this isn't basic javascript question, library question, , how "happens" depends on implementation.
this here sample implementation of every
in javascript:
function every(array, fn) { for(var = 0; < array.length; i++) { fn(array[i], i, array); } }
you phone call this:
every([1,2,3,4], function(item, index, array) { // stuff });
as can see, it's every
function itself, calls fn
(which function pass in), , decides arguments pass.
javascript function
No comments:
Post a Comment