![](/img/trans.png)
[英]How to tell Google Closure Compiler in simple mode that particular function name could be compressed?
[英]Tell the Closure Compiler not to rename any function
我想編譯基於Mootools庫的JS代碼的一部分。
我希望重命名所有變量,但不重命名任何函數,即已調用和已定義的函數。 因為大多數被調用對象來自mootools,而定義的對象則是從外部調用的:
要編譯的代碼:
// textnum is safe to be renamed, all variables are
textnum = 0;
// loadText can't be ranmed because is called from outside
function loadText()
{
textnum++;
document.body.setStyle("font", "12px");
// here setSyle can't be renamed
}
有沒有辦法告訴它僅重命名vars?
我發現這是一個開源項目,有沒有辦法完全不影響功能!
將要編譯的代碼放在名稱空間或匿名函數包裝器中,並使用簡單的優化。 這將重命名所有內部var和函數,但不會重命名全局變量和函數,例如setStyle
。
不應重命名的功能在全局范圍內定義。 與定義外部和出口相比,這並沒有那么痛苦。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.