const myO = {
myf: () => {
console.log(this);
},
};
myO.myf(); // this === window
In object literal, this refers to window;
class MyObject {
myf = () => {
console.log(this);
};
}
const myObject = new MyObject();
myObject.myf(); // this === MyObject
In an object instantiated from a class, this refers to the object.
Why is the difference?
Question is marked as duplicated but I really can't see any resemblance