I have recently started using dojo, I was wondering if there is anyway to implement a wrapper/adapter class. In pure javascript I would do the following
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
How do I do this with dojo. Something as such does not work
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
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);
精彩评论