dojo 包装器或适配器类

发布于 2024-10-31 10:25:53 字数 1038 浏览 0 评论 0原文

我最近开始使用 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

How do I do this with 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落 2024-11-07 10:25:53
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);

//或者

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);
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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文