In the following Javascript code, the first call to saveResult from writeData succeeds while the second doesn't, please help.
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();