Prototype in JavaScript
Jun 3, 2021
Objects in javascript have a prototype property which is a part of the constructor function that created it.
Two types of property is there for objects:
- Own property
- Prototype property
function Car(name) {
this.name = name; //own property
}
Car.prototype.wheel = 4; // prototype property
let car1 = new Car(“Maruti”);
Own property is defined directly on the object instance itself. And prototype properties are defined on the prototype.
Here is how you can understand the difference between these two properties.
We will push different properties in different arrays.
Here you can go through this example and Lets have a discussion.
Happy Learning.