Chaosy
Tutorial Reviewer
- Joined
- Jun 9, 2011
- Messages
- 13,239
I've got a a piece of code which basically looks like:
Which writes undefined because "this" refers to "this.something" instead of the instance.
Are there any ways to work around that?
Code:
class Name {
someFunc() {
console.log(this.x);
}
constructor() {
this.x = 1;
this.something.addEventListener("click", someFunc);
}
}
Which writes undefined because "this" refers to "this.something" instead of the instance.
Are there any ways to work around that?