In the following code, which is the correct way to inherit an object constructor's prototype? I want Admin's prototype to have the 'login' method that was previously attached to the User prototype. I've tried both and I'm not exactly sure which is the correct way.
function User(email, name) {
this.email = email;
this.name = name;
this.online = false;
}
User.prototype.login = function() {
this.online = true;
console.log(this.email, 'has logged in');
}
function Admin(...args) {
User.apply(this, args);
this.role = 'super admin';
}
Admin.prototype = Object.create(User.prototype); //option 1
Admin.prototype = User.prototype; //option 2