Object Oriented Programming - Make Code More Reusable with the this Keyword

What’s the problem with this code? I am trying to lconvert the code to ES6’s arrow function instead of the default but when I introduce “this” instead of “dog” it doesn’t work, What happened?

  **Your code so far**
let dog = {
name: "Spot",
numLegs: 4,
sayLegs: () => "This dog has " + this.numLegs + " legs.",
};

dog.sayLegs();
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: Object Oriented Programming - Make Code More Reusable with the this Keyword

Link to the challenge:

1 Like

I had similar confusion.
Consider to do research about arrow func-s. They are cool, but they have limitations.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.