const objectLiteral = { x: 5, getX: () => { console.log(`The value of x is ${this.x}`); } } x.getX(); // The value of x is undefined ¿Por qué this no se vincula con el método getX cuando uso un objeto literal? ¿La función de flecha no obtiene this del alcance principal? En este caso, el objectLiteral. Pero lo hace cuando uso un objeto generado por la clase.
class classObject { x = 5; getX = () => { console.log(`The value of x is ${this.x}`); } const classObjectInstance = new classObject(); classObjectInstance.getX(); // The value of x is 5 }