我最近开始使用dojo,我想知道是否还有实现包装器/适配器类。在纯JavaScript中我会做以下
function Person(name){
this.name=name;
}
function Employee(name,ID){
this.Person=Person;
this.Person(name);
this.ID=ID;
this.PromotedEmployee=PromotedEmployee;
}
function PromotedEmployee(employees){
this.employees=employees; //number of people working for him/her
}
var employee=new Employee("John Stamos",123);
employee.PromotedEmployee(10); //promote to manage 10 people
如何使用dojo执行此操作。这样的东西不起作用
dojo.declare("Person",null,{
constructor: function(name){
this.name=name;
}
});
dojo.declare("PromotedEmployee",null,{
constructor: function(employees){
this.employees=employees;
}
});
dojo.declare("Employee",[Person],{
constructor: function(name,ID){
this.ID=ID;
},
PromotedEmployee=PromotedEmployee;
});
var employee=new Employee("John Stamos",123);
employee.PromotedEmployee(10); //promote to manage 10 people
答案 0 :(得分:1)
dojo.declare("PromotedEmployee",null,{
employees: 0,
constructor: function(){
},
promoteEmployees: function(employees){
this.employees = employees;
}
});
dojo.declare("Employee",[Person],{
constructor: function(name,ID){
this.ID=ID;
this.promotedEmployee = new PromotedEmployee();
}
});
var employee=new Employee("John Stamos",123);
employee.promotedEmployee.promoteEmployees(10);
// OR
dojo.declare("PromotedEmployee",null,{
constructor: function(employees){
this.employees = employees;
}
});
dojo.declare("Employee",[Person],{
constructor: function(name,ID,employees){
this.ID=ID;
this.promotedEmployee = new PromotedEmployee(employees);
}
});
var employee=new Employee("John Stamos",123, 10);
//alert(employee.promotedEmployee.employees);