level 6
谁帮解释一下这段js的计算过程?
Array.prototype.each = function(closure) {
return this.length
?
[closure(this.slice(0, 1))].concat(this.slice(1).each(closure))
:
[]
;
}
alert([1,2,3,4].each(function(x){return x * 2}));
//注意,把全角空格“ ”替换为 半角“ ”。
2011年09月20日 09点09分
1
level 11
arrayObj.slice(start, [end])
如果省略 end ,那么 slice 方法将一直复制到 arrayObj 的结尾
array1.concat([item1[, item2[, . . . [, itemN]]]])
返回一个新数组,这个新数组是由两个或更多数组组合而成的。
其他就是最后的递归调用了
2011年10月17日 14点10分
3