I have the following code and have came across the call and prototype.constructor methods but don't have enough knowledge to make them work properly. Can some one fill in the knowledge I am missing. Here an Administrator is a User.
function User(user) {
this.id = user.id;
this.email = user.email;
this.firstname = user.firstname;
this.lastname = user.lastname;
this.age = user.age;
}
User.prototype.fullName = function(){
return this.firstname + ' ' + this.lastname
}
function Admin(admin){
this.writer = admin.writer;
this.editor = admin.editor;
this.publisher = admin.publisher;
//User.call(this);
}
Admin.prototype.fullAccess = function(){
return (this.writer && this.editor && this.publisher);
}
//Admin.prototype = new User();
//Admin.prototype.constructor = Admin;
var user1 = new User({
'id': 1,
'email': '[email protected]',
'firstname': 'Stephen',
'lastname': 'Brown',
'age': 44
});
var user2 = new User({
'id': 2,
'email': '[email protected]',
'firstname': 'John',
'lastname': 'Doe',
'age': 25
});
var admin1 = new Admin({
'writer': true,
'editor': true,
'publisher': true,
});
var admin2 = new Admin({
'writer': true,
'editor': true,
'publisher': false,
});