Possible Duplicate:
underscore's each checking for {} return of callback
I was taking a look at underscore's source and implementation of the Foreach method. I just have one question with the below method.
var breaker = {};
var each = _.each = _.forEach = function(obj, iterator, context) {
if (obj == null) return;
if (nativeForEach && obj.forEach === nativeForEach) {
obj.forEach(iterator, context);
} else if (obj.length === +obj.length) {
for (var i = 0, l = obj.length; i < l; i++) {
if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return;
}
} else {
for (var key in obj) {
if (_.has(obj, key)) {
if (iterator.call(context, obj[key], key, obj) === breaker) return;
}
}
}
};
I am struggling with the following line? Why check if the iterator being called is an empty object? Why would you return an empty object from the iterator?
if (iterator.call(context, obj[key], key, obj) === breaker) return;