簡體   English   中英

如何在ADVANCED_OPTIMIZATIONS中的Closure Compiler中導出公共類方法?

[英]How to export public class methods in Closure Compiler in ADVANCED_OPTIMIZATIONS?

我使用的是受John Resig啟發的JavaScript繼承,我的庫代碼如下所示:

var Person = Class.extend({
  /** @private */
  _dancing: null,

  /** @private */
  _init: function(isDancing){
    this._dancing = isDancing;
  },

  /** @public */ 
  dance: function(){
    return this._dancing;
  }
});

var obj = new Person();
obj.dance();

最好的方法是只處理那些以下划線開頭的類方法,並將所有公共方法保存在ADVANCED_OPTIMIZATIONS中。

我需要獲得以下輸出:

var a = Class.extend({a:null, b:function(b) {
  this.a = b;
}, dance:function() {
  return this.a;
}});
new a;
a.dance();

實現此目的的“最簡單”方法是為編譯器創建自定義編碼約定(必須修改編譯器)並將“導出”約定更改為不以“ _”開頭的任何內容。

看到:

http://closure-compiler.googlecode.com/svn/trunk/src/com/google/javascript/jscomp/GoogleCodingConvention.java

及其“ isExported”方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM