我有以下代碼,並且遇到了call和prototype.constructor方法,但沒有足夠的知識使它們正常工作。有人可以填寫我缺少的知識嗎?這裏的管理員是用戶。我如何讓一個Javascript類成爲另一個類的孩子
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,
});
[參考鏈接](http://alexsexton.com/blog/2013/04/understanding-javascript-inheritance/) –