Object Oriented Programming - Define a Constructor Function

Tell us what’s happening:
Don’t have issues in terms of test passing.
Just want to ask: we can’t use arrow functions for constructors like below?

  **Your code so far**
const Dog = () => {
this.name = 'someName';
this.color = 'someColor';
this.numLegs = 4;
}
  **Your browser information:**

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

Challenge: Object Oriented Programming - Define a Constructor Function

Link to the challenge:

No, you cannot use Arrow Functions for constructors. It is one of the limitations of using arrow functions (or you can as well say it is one of the rules come into play). See this for more details: JavaScript Arrow Functions @MDN.

There are two points of interest in the linked documentation:

  • Arrow functions don’t have their own bindings to this
  • Arrow functions cannot be used as constructors
1 Like

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