为原生js Array增加each方法

2026-01-17 16:30:55 作者:用户投稿
复制代码 代码如下:
   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/>");
});

联络方式:

4008905355

邮箱:9196886@qq.com

Q Q:9196886

微信二维码