Prototype ? why?

Prototype ? why?
0

#1

i didn’t understand the reason of declaring a property using prototype instead of the normal way


#2

Prototype is a default way to share common properties across multiple object instances in JavaScript. It is JavaScript way of enabling inheritance. This is a reason why every array can have access to array methods like .indexOf(), '.forEach()`, etc…

What you call normal way assigns a property only in the object that you assigned to. (You can’t even call it normal because assigning property to prototype is just normal, as well.)


#3

so there is no difference between using this

Bird.prototype.numLegs = 2;

and this

Bird.numLegs = 2;

?


#4

oh never mind i did a test for both of them actually the first one could add the property as a prototype to all the object while the second one did nothing :slight_smile: