【发布时间】:2019-02-19 01:24:25
【问题描述】:
我知道以这种方式向原型添加方法不是最好的,但我只是在测试。
Array.prototype.maap = function (transform) {
let mapped = [];
for (let element of this) {
mapped.push(transform(element));
}
return mapped;
}
console.log([0, 2, 3].maap(n => n / this.length));
我得到:
[NaN,无穷大,无穷大]。我认为问题在于“this.length”。
【问题讨论】:
标签: javascript scope this