根據文檔(https://developers.google.com/closure/compiler/docs/api-tutorial3#externs),當沒有外部聲明存在時(包括從外部位代碼使用函數/變量時),封閉編譯器似乎應該重命名變量。他們給出的例子是爲什麼Google Closure Compiler不重命名這些外部變量?
function makeNoteDom(noteTitle, noteContent, noteContainer) {
// Create DOM structure to represent the note.
var headerElement = textDiv(noteTitle);
var contentElement = textDiv(noteContent);
...
}
其中textDiv函數在全局範圍內由某種第三方庫聲明。它說textDiv應該是外部聲明,以防止重命名。
我的問題是 - 當我將此代碼或類似代碼放入Closure Compiler而沒有任何extern聲明時,爲什麼textDiv沒有重命名(這會破壞代碼),正如文檔所指出的那樣?
另外:http://code.google.com/p/closure-compiler/wiki/FAQ#Some_of_my_properties_are_getting_renamed,_but_some_aren't。 – John