自定义编写ES6的 filter 函数
function filter_(callback) {
const newArr = [];
for (let i in this)
if (callback)
if (callback(this[i], +i)) newArr.push(this[i]);
return newArr;
}
Object.defineProperties(Array.prototype, {
["filter_"]: {
'value': filter_,
'writable': false,
'configurable': false,
'enumerable': false
}
})
const arr = [1, 2, 4, 5, 6, 7, 8];
console.log(arr.filter_(function(i, s) {
console.log(i, s);
return s;
}))