I just read the underscope source code, and cannot get the point from this code:
_.each = _.forEach = function(obj, iterator, context) {
if (obj == null) return obj;
iterator = createCallback(iterator, context);
var i, length = obj.length;
if (length === +length) { // why +length?
for (i = 0; i < length; i++) {
iterator(obj[i], i, obj);
}
} else {
var keys = _.keys(obj);
for (i = 0, length = keys.length; i < length; i++) {
iterator(obj[keys[i]], keys[i], obj);
}
}
return obj;
};
why length===+length ? I guess this used for force to convert if length is not a number? Could somebody give me a hand?