代码:
if(typeof Array.prototype.map === 'function') {
Array.prototype.map = function(fn, context) {
let arr = [];
if(typeof fn === 'function') {
for(let i = 0, length = this.length; i < length; i++) {
arr.push(fn.call(context, this[i], i, this));
}
}
return arr;
};
}
let data = [1, 2, 3, 4];
data = data.map(function(item) {
return item + item;
});
console.log(data);