我有以下代码:
function test() {
}
test.prototype.ab = 77;
test.prototype.foo = () => ++this.ab; // arrow function
obj = new test();
console.log(obj.foo());
输出为NaN
,但是当我这样做时:
function test() {
}
test.prototype.ab = 77;
test.prototype.foo = function() {
return ++this.ab;
}
obj = new test();
console.log(obj.foo());