[英]How to create obfuscatable variables and functions in a javascript module?
我有一組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
文件中定義如下:
var B1 = "Some text";
var B2 = "More text";
...
function MyPrivateMethod1() { ... };
function MyPrivateMethod2() { ... };
混淆了a.js
的方法,但不混淆b.js
。 我可以在串聯文件中看到B1
, B2
, MyPrivateMethod1
, MyPrivateMethod1
...,但是我找不到a.js
的變量和方法(名稱已被混淆)。
如何在串聯文件中混淆b.js
的var和方法? (REM:我需要將b.js
保留為單獨的文件)。
我找到了解決方案,但是我不確定這是最好的解決方案。 我將b.js
的代碼移到了一個函數中:
var dummy = function() {
var B1 = "Some text";
var B2 = "More text";
...
var MyPrivateMethod1 = function() { ... };
var MyPrivateMethod1 = function() { ... };
...
function MyPublicMethod1() { ... };
function MyPublicMethod2() { ... };
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.