繁体   English   中英

如何通过Google Closure Compiler将功能标记为“私有”以重命名?

[英]How i can mark function as “private” to renaming it by Google Closure Compiler?

我有私有函数createSomething():

function Player(id) {

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

并且我想在使用Google Closure Compiler编译源代码后看到重命名的函数“ createSomething()”。 是的,我知道ADVANCED_OPTIMIZATIONS,但它与jQuery和其他库不兼容。

解决方案是使用字符串文字来引用属性。

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

之所以可行,是因为编译器从不重命名字符串文字。 不过要小心。

您可以使用ADVANCED_OPTIMIZATIONS编译代码,但仍与其他库兼容。 你需要了解的库文件中实习医生出口

不用这个就可以使用

function Player(id) {

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM