我有以下代码,并且遇到了 call 和 prototype.constructor 方法,但没有足够的知识使它们正常工作。有人可以填补我所缺少的知识。这里的管理员是用户。
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': 'sd_brown@ntlworld.com',
'firstname': 'Stephen',
'lastname': 'Brown',
'age': 44
});
var user2 = new User({
'id': 2,
'email': 'johndoe@ntlworld.com',
'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,
});