// forEach
Array.prototype.forEach = function(cb){
var _arr = this
var _len = _arr.length
var _arg2 = arguments[1] || window
for(let i = 0 ; i < _len ; i++){
cb.apply(_arg2,[_arr[i],i,_arr])
}
}
// map
Array.prototype.map = function(cb){
var _arr = this
var _len = _arr.length
var _arg2 = arguments[1] || window
var _newArr = []
var _item
var res
for(let i = 0 ; i < _len ; i++){
_item = deepClone(_arr[i]) // 深拷贝
res = cb.apply(_arg2,[_item,i,_arr])
if(res){
_newArr.push(res)
}
}
return _newArr
}
// filter
Array.prototype.filter = function(cb){
var _arr = this
var _len = _arr.length
var _arg2 = arguments[1] || window
var _newArr = []
var _item
for(let i = 0 ; i < _len ; i++){
_item = deepClone(_arr[i]) // 深拷贝
cb.apply(_arg2,[_item,i,_arr]) ? _newArr.push(item) : ''
}
return _newArr
}