_.map = _.collect = function(obj, iteratee, context) {
iteratee = cb(iteratee, context);
// 这里的keys是希望得到一个数组吧,而实际源码中会得到一个Boolean值
// 是否应该换成这种写法?keys = !isArray(obj) ? _.keys(obj) : void 0
var keys = !isArrayLike(obj) && _.keys(obj),
length = (keys || obj).length,
results = Array(length);
for (var index = 0; index < length; index++) {
var currentKey = keys ? keys[index] : index;
results[index] = iteratee(obj[currentKey], currentKey, obj);
}
return results;
};
30秒到达战场
相关分类