简体   繁体   English

如何在ADVANCED_OPTIMIZATIONS中的Closure Compiler中导出公共类方法?

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

I'm using JavaScript inheritance inspired by John Resig and my library code looks like the following: 我使用的是受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();

What's the best way to mangle only those class methods that starts with underscore and save all public methods in ADVANCED_OPTIMIZATIONS. 最好的方法是只处理那些以下划线开头的类方法,并将所有公共方法保存在ADVANCED_OPTIMIZATIONS中。

I need to get the following output: 我需要获得以下输出:

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

The "easiest" way to do this would be to create a custom coding convention for the compiler (you have to modify the compiler) and change the "export" convention to be anything not starting with "_". 实现此目的的“最简单”方法是为编译器创建自定义编码约定(必须修改编译器)并将“导出”约定更改为不以“ _”开头的任何内容。

See: 看到:

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

and its "isExported" method. 及其“ isExported”方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有Closure Compiler和ADVANCED_OPTIMIZATIONS的模块模式 - Module pattern with Closure Compiler and ADVANCED_OPTIMIZATIONS 使用闭包编译器 ADVANCED_OPTIMIZATIONS 的奇怪对象属性行为 - strange object property behavior with closure compiler ADVANCED_OPTIMIZATIONS Google Closure Compiler ADVANCED_OPTIMIZATIONS - 排除所有函数名称 - Google Closure Compiler ADVANCED_OPTIMIZATIONS - Exclude All function names 是否可以使用闭包编译器ADVANCED_OPTIMIZATIONS与jQuery? - Is it possible to use Closure Compiler ADVANCED_OPTIMIZATIONS with jQuery? Google Closure编译器的ADVANCED_OPTIMIZATIONS选项 - Google Closure Compiler's ADVANCED_OPTIMIZATIONS option 如何不编译goog.closure中的某些代码ADVANCED_OPTIMIZATIONS - How to not compile certain code in goog.closure ADVANCED_OPTIMIZATIONS 关闭编译ADVANCED_OPTIMIZATIONS抱怨使用此方法 - closure compilation ADVANCED_OPTIMIZATIONS complaining about use of this 具有高级优化和外部功能的Closure编译器 - Closure Compiler with Advanced Optimizations and Externs 闭包编译器,缺少具有高级优化功能的方法? - Closure Compiler, missing method with advanced optimizations? 是否可以避免使用带有getter和setter的模式,而仍然使用Closure ADVANCED_OPTIMIZATIONS最小化JavaScript? - Can a pattern with getters and setters be avoided and still minify JavaScript with Closure ADVANCED_OPTIMIZATIONS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM