【发布时间】:2012-07-17 16:10:07
【问题描述】:
我有一个 Pers(on) 和一个从 Pers 派生的 Employee。
Pers = function(options){
this.Name;
this.ID;
this.init = function(options){
this.Name=options.Name;
this.ID=options.ID;
}
}
Employee = function(options){
this.Sal;
this.init = function(options){
this.Sal=options.Sal;
this.__proto__.init(options);
}
this.init(options);
}
Employee.prototype=new Pers();
现在当我创建新对象时...
var o=new Employee({Name:"Nik",ID:"1",Sal:100});
var p=new Employee({Name:"Tanja",ID:"2",Sal:200});
并提醒他们的名字,我会得到两次“Tanja”。
有人有想法吗?
【问题讨论】:
-
很确定你不应该再使用
__proto__了。
标签: javascript object prototype