给js原生Array增加each方法

来源:岁月联盟 编辑:exp 时间:2012-04-06

Array.prototype.each = function(fn)
    {
        return this.length ? [fn(this.slice(0,1))].concat(this.slice(1).each(fn)) : [];
    };
   
    [1,2,3,4].each(function(x){
        document.write(x + "<br/>");
    });
   

 

摘自  木之原