How does Javascript match the parameters in the callback function? -
i started learn javascript, , callback functions seem hard understand. 1 question have how javascript matches parameters in callback function? example in following foreach loop:
var friends = ['mike', 'stacy', 'andy', 'rick']; friends.foreach(function(eachname, index){ console.log(index + 1 + ". " + eachname); });
is default foreach function pass index second parameter , entry first parameter in callback function?
in order master callback functions, need check api (in case, foreach) every time use it?
is default foreach function pass index second parameter , entry first parameter in callback function?
yes; this part of specification. in fact, passes array being iterated third argument.
call [[call]] internal method of callbackfn t value and argument list containing [the value], [the index], , [the object].
(emphasis mine.)
in order master callback functions, need check api (in case, foreach) every time use it?
well, they’re pretty consistent each other, you’ll remember @ point. map
, filter
, every
, , some
work in way.
Comments
Post a Comment