[英]How i can mark function as “private” to renaming it by Google Closure Compiler?
I have private function createSomething(): 我有私有函数createSomething():
function Player(id) {
/**
* Creates stuff
* @private
*/
this.createSomething = function() {
// do something good
};
}
and I want to see the renamed function "createSomething()" after compiling the source with Google Closure Compiler. 并且我想在使用Google Closure Compiler编译源代码后看到重命名的函数“ createSomething()”。 Yes, I know about ADVANCED_OPTIMIZATIONS but it is incompatible with jQuery and other libraries. 是的,我知道ADVANCED_OPTIMIZATIONS,但它与jQuery和其他库不兼容。
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. 您可以使用ADVANCED_OPTIMIZATIONS编译代码,但仍与其他库兼容。 You'll need to read about externs and exports in the library documentation: 你需要了解的库文件中实习医生和出口 :
Just use without this 不用这个就可以使用
function Player(id) {
/**
* Creates stuff
* @private
*/
createSomething = function() {
// do something good
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.