为什么我得到“构造函数必须在声明时初始化”google封闭编译器警告?

时间:2013-06-10 14:09:46

标签: javascript annotations google-closure-compiler

考虑这段代码:

AEP: {
    Module: {
        _instances: {},
        get: function(module) {
            return (AEP.Module._instances[module.id] || (AEP.Module._instances[module.id] = new AEP.Module.Instance(module)));
        },
        implement: function(module, implementation) {
            AEP.Module.get({id: module}).dispatch(implementation(AEP));
        },
        /**
         * @param module
         * @constructor
         */
        Instance: function(module) {
            AEP.Event.apply(this, arguments);
            AEP.Utility.loadJSFile(module.url);
        }
    }
//...
}

我收到GCC警告:

WARNING - Constructor AEP.Module.Instance must be initialized at declaration

为什么?

2 个答案:

答案 0 :(得分:1)

我猜测检查无法将标签识别为作业。试试这个:

AEP: {
    Module: {
        _instances: {},
        get: function(module) {
            return (AEP.Module._instances[module.id] || (AEP.Module._instances[module.id] = new AEP.Module.Instance(module)));
        },
        implement: function(module, implementation) {
            AEP.Module.get({id: module}).dispatch(implementation(AEP));
        },
        Instance:
          /**
           * @param module
           * @constructor
           */
          function(module) {
            AEP.Event.apply(this, arguments);
            AEP.Utility.loadJSFile(module.url);
          }
    }
//...
}

答案 1 :(得分:0)

Crazy Train已经解释过;这是一个例子:

var AEP= {
    Module: {
        _instances: {},
        get: function(module) {
            window['console'].log("get");
        },
        implement: function(module, implementation) {
            window['console'].log("implement");
        }
    }
};
/**
* @param module
* @constructor*/
AEP.Module.Instance= function(module) {
  window['console'].log("instance");
};