给js原生Array增加each方法

复制代码
   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/>");
});
复制代码
posted @   水之原  阅读(2269)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示