全局命名空间 Javascript 错误
Global Namespace Javascript Error
var NS = NS|{};
NS.A = {
prop1: 'hello',
prop2: 'there',
func: function() {alert('boo');}
};
NS.A.func()
以上代码给出NS.A is undefined 错误。
如果我声明 NS 如下它有效
var NS = {};
帮助我理解 why.I 我正在尝试使用中定义的全局命名空间
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript
这实际上应该可行,只是第一行有错别字。
您有:var NS = NS|{};
你应该有:var NS = NS||{};
This article解释这种评价
var NS = NS|{};
NS.A = {
prop1: 'hello',
prop2: 'there',
func: function() {alert('boo');}
};
NS.A.func()
以上代码给出NS.A is undefined 错误。 如果我声明 NS 如下它有效
var NS = {};
帮助我理解 why.I 我正在尝试使用中定义的全局命名空间 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript
这实际上应该可行,只是第一行有错别字。
您有:var NS = NS|{};
你应该有:var NS = NS||{};
This article解释这种评价