考虑这段代码:
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
为什么?
答案 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");
};