I'm analyzing the behavior of this in classes and object and have one question which doesn't give me peace. I have this code-snippet:
const obj = {
a: 5,
say: () => console.log(this.a)
}
obj.say(); // will log undefined
class A {
constructor() {
this.a = 15;
}
say = () => console.log(this.a);
}
const a = new A();
a.say(); // will log 15
Why it works with classes examples, but not with singe object?
As I understand it, there is some difference between declaring methods in objects and declaring class methods. But which one?