我的 javascript 代码有一个大问题,基本上我找不到为什么我的 ListMgr 没有定义...
我加载了 ListMgr.js(现在看起来像这样):
var ListMgr = {
maxItems : 6,
currentItems : 1,
initialize : function (_maxItems, _currentItems) {
if (_maxItems === undefined) {
_maxItems = 6;
}
if (_currentItems === undefined) {
_currentItems = 1;
}
this.maxItems = _maxItems;
this.currentItems = _currentItems;
};
};
然后在我的 html 文件中我有:
$(document).ready(function(){
var mgr = new ListMgr();
mgr.initialize(10, 1);
});
它抛出
Uncaught ReferenceError: ListMgr is not defined.
任何帮助将不胜感激 - 我相信这里的一切都应该是正确的,但我可能会弄错。
最佳答案
ListMgr
是一个对象而非函数,因此您不能将其作为 new ListMgr()
调用。您可能想使用 Object.create()
相反。
$(document).ready(function(){
var mgr = Object.create(ListMgr);
mgr.initialize(10, 1);
});
关于JavaScript 未捕获引用错误 : ListMgr is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33366724/