![](/img/trans.png)
[英]How can I tell Closure compiler that something exists in a separate file?
[英]How can I tell Google closure compiler to not remove a var
我有以下代码:
// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// ==/ClosureCompiler==
var l = window.location;
var s = 'hash';
l[s] = 'whatever i need now';
使用谷歌关闭编译器(高级模式)进行编译,如下所示:
window.location.hash="whatever i need now";
但是在这种情况下,我确实需要它在编译后的代码中继续使用l[s]= ...
有没有办法告诉编译器继续使用var或忽略几行?
使散列函数与Junos Pulse一起正常工作是一个小技巧。
我很难相信有必要进行黑客入侵,但是:
// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// ==/ClosureCompiler==
eval(
"var l = window.location;\n" +
"var s = 'hash';\n" +
"l[s] = 'whatever i need now';\n"
);
*骇* *咳** :-)
要么:
// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// ==/ClosureCompiler==
sessionStorage.x = "hash";
window.location[sessionStorage.x] = 'whatever i need now';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.