JS模拟实现ECMAScript5新增的数组方法(2)

Array.prototype.newReduceRight = function(fn){ if(this.length === 0){ throw new TypeError('Reduce of empty array with no initial value'); } var result; for(var i = this.length - 1; i >= 0; i--){ if(i in this){ if(!result){ result = this[i]; }else{ result = fn(result, this[i], i, this); } } } return result; }; var a = [,,1,2,3,4,,6,7]; console.log(a.newReduceRight(function(a,b){ console.log(arguments); return a + b; }))

以上所述是小编给大家介绍的JS模拟实现ECMAScript5新增的数组方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwwypz.html