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

Why does this not work? Can’t we use “this” keyword in arrow functions?

Your code so far

let dog = {
  name: "Spot",
  numLegs: 4,
  // sayLegs: function() {return "This dog has " + this.numLegs + " legs.";}
  sayLegs : () => `This dog has ${this.numLegs} legs.`
};

dog.sayLegs();

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

Link to the challenge:

1 Like

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