Array.prototype.each

Array.prototype.each = function(closure){
    //递归合并
    return this.length ? [closure(this.slice(0,1))].concat(this.slice(1).each(closure)) : [];
}
[1,2,3,4].each(function(x){return x*2}); //2,4,6,8
[1,2,3,4].each(function(x){return x-1}); //0,1,2,3
原文地址:https://www.cnblogs.com/lecaf/p/3272078.html