классы оболочки или адаптера Dojo - PullRequest
0 голосов
/ 12 апреля 2011

Я недавно начал использовать 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

1 Ответ

1 голос
/ 12 апреля 2011
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);
...