I am having a problem understanding why the following does not work. I looked at the other suggested answers and none of them addresses this clearly in the context of a new class object.
Given the code below:
class Example1 {
constructor(v1) {
this.v1 = v1;
}
method1() {
console.log("v1 value = ",this.v1)
}
}
const example1 = new Example1("value1");
const alias1 = example1.method1;
example1.method1();
alias1();
When I call alias1()
, why is this
undefined
?