[英]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.