javascript - Why is the object being iterated passed back through the callback? -
this common idiom encapsualted function undescore.
_.each(obj1, function(val, key, context, obj2){ });
what purpose of 4th argument in callback - obj2
. object 1 looping through should available in outer scope obj1
.
is there example of need access obj1
through obj2
.
i'm trying understand obj2
for. here exact line of code - line 83.
if (iterator.call(context, obj[i], i, obj) === breaker) return;
if passing reference named function callback, obj1
might not available:
function my_callback(val, key, context, obj2) { ... } function do_stuff() { var obj1 = ... _.each(obj1, my_callback); }
Comments
Post a Comment