gpt4 book ai didi

Javascript 无法从使用此调用的方法设置属性

转载 作者:行者123 更新时间:2023-11-30 19:48:21 25 4
gpt4 key购买 nike

<分区>

在下面的 Javascript 代码中,第一次从 writeData 调用 saveResult 成功,而第二次没有成功,请帮助。

class SimpleClass {

constructor() {
this.ir = "";
}

saveResult(res) {
console.log("entered save result")
this.ir = res;
console.log("value saved is " + this.ir);
console.log("end save result");
}

writeData() {
this.saveResult("abc"); //works fine

var sr = this.saveResult;
sr("abc"); //throws error -> Cannot set property 'ir' of undefined
}
} //end of class

function testLocally() {
var sc = new SimpleClass();
var wr = sc.writeData();
console.log("done");
}

testLocally();

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com