Why do we need THIS key word in constructors?

411 views

Particularly in JavaScript object oriented programming:

If I have a class like this, for example:

class Animals{
constructor(name, species){
this.name = name;
this.species = species;
}
}

Why do we need to use this.yyyy = yyyy in the constructor? I have read explanations many times but still can’t get it, please explain like I’m 5

In: 28

6 Answers

Anonymous 0 Comments

there are two variables named “species” in the contexts. The function parameter and the object property.

You are viewing 1 out of 6 answers, click here to view all answers.