Array.prototype.filter = function (callback) {
if (!(callback instanceof Function)) {
throw new Error('filter 傳參不是函數')
}
var resultArr = []
// this 就是調用filter的這個數組
for (var i = 0; i < this.length; i++) {
if (callback(this[i])) { // 是true 把item返回給傳進來的函數 讓它自己校驗返回true還是false
resultArr.push(this[i])
}
}
return resultArr
}
this 指向調用的數組