如何在 JavaScript 模块中创建可混淆的变量和函数?
我有一组 js 文件,在编译时连接成一个唯一的文件,然后在其上运行 YUI 压缩器(全部在 maven 下)。
不幸的是,文件的内容并没有被混淆。就好像所有声明的变量和方法都被认为是公共的(因此不可混淆)。
例如,a.js
使用 b.js
中声明的方法。拼接文件的内容为:
(function() {
// b.js' content...
// a.js' content...
(function() {
// Some var and methods of a declared here
$(document).ready(function(){
// Calls some a.js and b.js methods
...
});
})();
})();
b.js 的函数和变量在 b.js 文件中定义如下: a.js
var B1 = "Some text";
var B2 = "More text";
...
function MyPrivateMethod1() { ... };
function MyPrivateMethod2() { ... };
的方法 已被混淆,但 b.js
的未混淆。我可以在串联文件中看到 B1
、B2
、MyPrivateMethod1
、MyPrivateMethod1
...,但找不到a.js
的变量和方法(名称已被混淆)。
如何混淆连接文件中 b.js
的 var 和方法? (REM:我需要将 b.js
保留为单独的文件)。
I have a set of js files I concatenate into a unique file at compile time, before running YUI compressor on it (all under maven).
Unfortunately, the content of a file is not obfuscated. It is as if all declared variables and methods were considered public (and therefore not obfuscatable).
For example a.js
uses methods declared in b.js
. The content of the concatenated file is:
(function() {
// b.js' content...
// a.js' content...
(function() {
// Some var and methods of a declared here
$(document).ready(function(){
// Calls some a.js and b.js methods
...
});
})();
})();
The functions and variables of b.js
are defined as following in the b.js
file:
var B1 = "Some text";
var B2 = "More text";
...
function MyPrivateMethod1() { ... };
function MyPrivateMethod2() { ... };
The methods of a.js
are obfuscated, but not those of b.js
. I can see B1
, B2
, MyPrivateMethod1
, MyPrivateMethod1
... in the concatenated file, but I cannot find the variables and methods of a.js
(the names have been obfuscated).
How can I obfuscate the var and methods of b.js
in the concatenated file? (REM: I need to keep b.js
as a separate file).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个解决方案,但我不确定它是最好的。我将
b.js
的代码移至函数中:I found a solution, but I am not sure it is the best one. I moved
b.js
's code in a function: