在构造函数中调用函数

时间:2014-01-03 18:18:21

标签: javascript dojo

我想在创建对象时调用函数。反正有吗?

return declare("myObject", mySuperObject, {
    constructor: function (args) {

        test();

        lang.mixin(this, args);
    },
    test: function () {
        console.log('test');
    }
});

这导致ReferenceError: test is not defined

1 个答案:

答案 0 :(得分:1)

改为使用this.test()

return declare("myObject", mySuperObject, {
    constructor: function (args) {

        this.test();

        lang.mixin(this, args);
    },
    test: function () {
        console.log('test');
    }
});