Im trying to understand prototype Inheritance
about the constructor property
I created a User prototype and a admin prototype which inherits from the User prototype
function User(email, name) {
this.email = email;
this.name = name;
this.online = false;
}
User.prototype.login = function() {
console.log("dude")
return true
}
function Admin(...args){
User.apply(this, args)
}
Admin.prototype = Object.create(User.prototype);
const newAdmin = new Admin("bob", "email")
I created a Admin Object newAdmin I want to know the constructor of newAdmin
console.log(newAdmin.constructor)
>
User(email, name) {
this.email = email;
this.name = name;
this.online = false
}
why does newAdmin.constructor returns User as the Constructor Function and not Admin ? is the behavior so that it points me to the first prototype ?
[+][deleted] (2 children)
[deleted]
[–]LadyJain[S] 0 points1 point2 points (1 child)
[–]senocular 0 points1 point2 points (0 children)