闭包编译器对命名空间枚举发出警告
以下示例代码生成有关高级优化的编译器警告:“JSC_UNSAFE_NAMESPACE:为命名空间 NS 创建的不完整别名”。如果我删除 @enum 注释,它不会发出警告。
var NS = {};
/**
* @enum {string}
*/
NS.type = {
FOO : 'bar'
};
NS.foobar = function(){ alert(NS.type.FOO); };
window['NS'] = NS;
window['NS']['foobar'] = NS.foobar;
仅导出函数而不导出命名空间似乎也有效:
window['NS_foobar'] = NS.foobar;
我做错了什么?有办法解决这个问题吗?如果可能的话,我宁愿不包含 Closure 库。
The following sample code generates a compiler warning on advanced optimization: "JSC_UNSAFE_NAMESPACE: incomplete alias created for namespace NS". If I remove the @enum comment, it doesn't give the warning.
var NS = {};
/**
* @enum {string}
*/
NS.type = {
FOO : 'bar'
};
NS.foobar = function(){ alert(NS.type.FOO); };
window['NS'] = NS;
window['NS']['foobar'] = NS.foobar;
Exporting only the function and not the namespace also seems to work:
window['NS_foobar'] = NS.foobar;
What am I doing wrong? Is there a way around this? I'd rather not include the Closure library if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译器希望将枚举值折叠为单个变量:
NS.type.FOO 变为 NS$type$FOO。您导出的“NS”不会包含您期望的内容。
我怀疑你想要这样的东西:
The compiler expects to collapse the enum value into single variables:
NS.type.FOO becomes NS$type$FOO. The "NS" that you exported would not contain what you expect.
I suspect you want something like this: