开发者

How i can mark function as "private" to renaming it by Google Closure Compiler?

开发者 https://www.devze.com 2022-12-17 12:09 出处:网络
I have private function createSomething(): function Player(id) { /** *Creates stuff *@private */ this.createSomething = function() {

I have private function createSomething():

function Player(id) {

  /**
   *  Creates stuff
   *  @private
   */
  this.createSomething = function() {
    // do something good
  };
}

and I want to see the renamed function "createSomething()" after compi开发者_JS百科ling the source with Google Closure Compiler. Yes, I know about ADVANCED_OPTIMIZATIONS but it is incompatible with jQuery and other libraries.


The solution is to use a string literal to refer to the property.

function Player(id) {
  /**
   *  @private
   */
  this['createSomething'] = function() {
    // do something good
  };
}

This works because the compiler never renames string literals. But be careful.

You can compile your code with ADVANCED_OPTIMIZATIONS and still have you compatibility with other libraries. You'll need to read about externs and exports in the library documentation:

  • http://code.google.com/closure/compiler/docs/api-tutorial3.html
  • http://code.google.com/closure/compiler/docs/limitations.html


Just use without this

function Player(id) {

  /**
   *  Creates stuff
   *  @private
   */
  createSomething = function() {
    // do something good
  };
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号