参考答案:
1Array.prototype.forEach = function(callback, thisArg) { 2 if (this == null) { 3 throw new TypeError('this is null or not defined'); 4 } 5 if (typeof callback !== "function") { 6 throw new TypeError(callback + ' is not a function'); 7 } 8 const O = Object(this); 9 const len = O.length >>> 0; 10 let k = 0; 11 while (k < len) { 12 if (k in O) { 13 callback.call(thisArg, O[k], k, O); 14 } 15 k++; 16 } 17}
最近更新时间:2021-07-07