数组⽅法的重写/**
* 数组扩展⽅法重写
*/
forEach=function(cb){
var _arr =this
var _len =this.length
var _th = arguments[1]|| window
for(var i =0; i < _len; i++){
cb.apply(_th,[_arr[i], i, _arr])
}
}
ap=function(cb){
var _arr =this
var _len =this.length
var _th = arguments[1]|| window
var _newArr =[]
var _item;
for(var i =0; i < _len; i++){
typeof _arr[i]==='object'? _item =deepCopy(_arr[i]): _item = _arr[i]
_newArr.push(cb.apply(_th,[_item, i, _arr]))
}
return _newArr
}
filter=function(cb){
var _arr =this
typeof arrayvar _len =this.length
var _th = arguments[1]|| window
var _newArr =[]
var _item;
for(var i =0; i < _len; i++){
typeof _arr[i]==='object'? _item =deepCopy(_arr[i]): _item = _arr[i]
cb.apply(_th,[_item, i, _arr])? _newArr.push(_item):""
}
return _newArr
}
very=function(cb){
var _arr =this
var _len =this.length
var _th = arguments[1]|| window
var _status =true
for(var i =0; i < _len; i++){
if(!cb.apply(_th,[_arr[i], i, _arr])){
_status =false
break
}
}
return _status
}
some=function(cb){
var _arr =this
var _len =this.length
var _th = arguments[1]|| window
var _status =false
for(var i =0; i < _len; i++){
if(cb.apply(_th,[_arr[i], i, _arr])){
_status =true
break
}
}
}
return _status
}
duce=function(cb,initvalue){ var _arr =this
var _len =this.length
var _th = arguments[2]|| window
for(var i =0; i < _len; i++){
initvalue=cb.apply(_th,[initvalue,_arr[i], i, _arr]) }
return initvalue
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。