处理数组的forEach
//forEach处理
if(!Array.prototype.forEach) {
Array.prototype.forEach = function (callback) {
for(var i=0,len=this.length;i<len;i++) {
callback(this[i], i);
}
}
}
处理数组的map
//处理map
if(!Array.prototype.map) {
Array.prototype.map = function (callback) {
var arr = [];
for(var i=0,len=this.length;i<len;i++) {
arr.push(callback(this[i], i));
}
return arr;
}
}
//处理数组的filter
//处理filter
if(!Array.prototype.filter) {
Array.prototype.filter = function (callback) {
var arr = [];
for(var i=0,len=this.length;i<len;i++) {
if(callback(this[i], i)) {
arr.push(this[i])
}
}
return arr;
}
}