Array.prototype._map = function (callback) {
const arr = JSON.parse(JSON.stringify(this))
if (!Array.isArray(arr)) throw new Error(`${this} in not by Array`)
const res = []
for (const [index, item] of arr.entries()) {
res.push(callback(item, index))
}
return res
}
实现map方法
最新推荐文章于 2024-04-08 21:12:50 发布