由原数组中每个元素执行回调函数后的结果组成新数组
// 数组map 实现
Array.prototype.fakeMap = function fakeMap(fn, context) {
if (typeof fn !== "function") {//判断fn是否能为函数,如果不是,跑出错误
throw new TypeError(`${fn} is not a function`);
}
let arr = this;
let temp = [];
for (let i = 0; i < arr.length; i++) {
// 迭代执行
let result = fn.call(context, arr[i], i, arr);
temp.push(result);
}
return temp;
};