I am having tough time understanding the use of this keyword inside a class.
For example I have a class having a method like this (if this classifies as ES7 Syntax)
class something {
methodA = () => {
this.something = "Hey"
}
methodB = () => {
this.something = "Yo"
}
}
[Question] Will this be a valid syntax? Usually I have seen people creating constructor where they declare most of the stuff but then again that is ES6 hence they need to things like this.count = 0;
inside a constructor for example...
class Clicker {
constructor(element) {
this.count = 0;
this.elem = element;
this.elem.addEventListener('click', this.click);
// logs Clicker { count:0, elem: button#thing} as expected
console.log(this);
}
click= () => {
console.log(this);
this.count++;
}
Answer to this question wasn't exactly much of a help to me "This" within es6 class method
If my above (class something) is wrong when using this keyword, can someone share any interesting articles about use of this keyword inside a class method in ES7