0

I'm using JavaScript inheritance inspired by John Resig and my library code looks like the following:

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.

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();
Erik
  • 14,060
  • 49
  • 132
  • 218

1 Answers1

0

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

and its "isExported" method.

John
  • 5,443
  • 15
  • 21
  • Thanks for the response. But do you mean that is if class method or property ends with underscore that it will be exported? – Erik Oct 17 '13 at 03:29
  • The coding conventions John mentioned have a method `isExported` which is used to determine if any symbol should be protected from renaming. You could change your custom coding convention to return true if the symbol does not start with an "_". This is not default behavior. – Chad Killingsworth Oct 17 '13 at 10:54
  • Is it possible to make any extention instead editing source code? – Erik Oct 18 '13 at 11:52
  • You can set the coding convention using the java api, so you should be able to maintain the code externally but you have to write java code at some point. – John Oct 19 '13 at 06:03
  • I use grunt closure compiler https://github.com/gmarty/grunt-closure-compiler Is it possible to make by using this tool? – Erik Oct 19 '13 at 16:24
  • I can't help you with grunt. I suggest you open another question like : how can I run a custom version of the Closure Compiler with grunt. – John Oct 21 '13 at 15:45