Using the Javascript Designer Prototype

When creating an object (before ES6), you can create an instance of the object this way ...

var Animal = function(){}

and then

var dog = new Animal();

...

Inside the "class" of animals, you can add ...

var Animal = function( name ){

   this.constructor.prototype.name = name;

}

The main question is: what is the difference between using regular thisversus usingthis.constructor.prototype

var Animal = function( name ){

   // what is the difference between this
   this.constructor.prototype.name = name;

   // and that
   this.name = name;

}

I know such a basic one if someone wants to explain. Thanks in advance!

+4
source share

Source: https://habr.com/ru/post/1689905/


All Articles