What is the correct fix?
const obj = {
value: 10,
getValue: () => {
return this.value;
},
};
console.log(obj.getValue());
- Use a method shorthand
getValue() { return this.value; } - Change
this.valuetoobj.valuein the arrow - Add
.bind(obj)to the arrow function body - Change
value: 10tolet value = 10above
Arrow functions have no own
Play Problem Solving ▸
this; use a normal method.