$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #44

What is the correct fix?

const obj = {
  value: 10,
  getValue: () => {
    return this.value;
  },
};
console.log(obj.getValue());
  1. Use a method shorthand getValue() { return this.value; }
  2. Change this.value to obj.value in the arrow
  3. Add .bind(obj) to the arrow function body
  4. Change value: 10 to let value = 10 above
Arrow functions have no own this; use a normal method.
Play Problem Solving ▸