【发布时间】:2012-01-19 02:15:05
【问题描述】:
我有我的 javascript 文件:
foo.js
var FooNS = {
T:5,
S: FooNS.T+5, //ERROR1
doSomething : function(adder)
{
//Do Something here.
}
};
这是我的另一个 js 文件:
useFoo.js
$(document).ready(function()
{
FooNS.doSomething(5); //ERROR2
});
这是我在包含 js 的页面上看到的两个 Javascript 错误(通过 Chrome Inspector):
- ERROR1 -> Uncaught TypeError: Cannot read property 'T' of undefined (foo.js)
- ERROR2 -> Uncaught TypeError: Cannot call method 'doSomething' of undefined (in useFoo.js)
我无法弄清楚这些错误的原因/命名空间的正确用法。有什么建议吗?
【问题讨论】:
标签: javascript jquery namespaces external undefined