JS inheritance when we crate object with constructor
Hi, if we are creating objects with a constructor, the prototype of this new object will point to a property named prototype of the function object.
The prototype property is an object with one property named constructor.
The constructor property points to the function itself:
function User() {
this.name = "Cristina Rojas";
}
let myObject = new User();
console.log(
"myObject.__proto__.constructor --->",
myObject.__proto__.constructor
);
Result:
Also if we check:
function User() {
this.name = "Cristina Rojas";
}
let myObject = new User();
console.log(myObject.__proto__ == User.prototype);
Result:
By Cristina Rojas.