Javascript 为什么InfoBubble.js作者用括号符号重新分配原型方法?

Javascript 为什么InfoBubble.js作者用括号符号重新分配原型方法?,javascript,google-maps,infobubble,Javascript,Google Maps,Infobubble,从GoogleMaps实用程序库中查看,我发现作者使用点符号创建了原型方法,但在方法定义的末尾,他使用括号符号重新分配了相同的原型属性 这应澄清: /** * Set the style of the shadow * * @param {number} shadowStyle The style of the shadow. */ InfoBubble.prototype.setShadowStyle = function(shadowStyle) { this.set('shad

从GoogleMaps实用程序库中查看,我发现作者使用点符号创建了原型方法,但在方法定义的末尾,他使用括号符号重新分配了相同的原型属性

这应澄清:

/**
 * Set the style of the shadow
 *
 * @param {number} shadowStyle The style of the shadow.
 */
InfoBubble.prototype.setShadowStyle = function(shadowStyle) {
  this.set('shadowStyle', shadowStyle);
};
InfoBubble.prototype['setShadowStyle'] = InfoBubble.prototype.setShadowStyle;

有什么想法吗?

除非某个浏览器中有bug,否则我看不出有什么原因。

我想我已经解决了

这种明显的胡说八道似乎与谷歌闭包编译有关

/**
 * Set the style of the shadow
 *
 * @param {number} shadowStyle The style of the shadow.
 */
InfoBubble.prototype.setShadowStyle = function(shadowStyle) {
  this.set('shadowStyle', shadowStyle);
};
InfoBubble.prototype['setShadowStyle'] = InfoBubble.prototype.setShadowStyle;
汇编至:

k.prototype.ma=function(a){this.set("shadowStyle",a)};
k.prototype.setShadowStyle=k.prototype.ma;
如您所见,点表示法
.setShadowStyle
缩小为
.ma
,通过使用缩小的形式,允许内部调用尽可能简洁

但是,由于这是一个公共方法,因此有必要提供一种方法,以其原始名称调用该方法。这是通过让编译器只最小化点符号而不是关联符号来实现的

因此,每个人都是快乐的;内部缩小和外部可访问性

我无法解释的是,为什么编译器不能简单地自行确定它需要保留原始名称以供公众使用。就我所见,它可以通过检测方法的前序块中不存在
@private
标记来实现

也许:

  • 闭包编译器还没有那么聪明,或者
  • 在编写InfoBubble时,闭包编译器没有那么聪明,或者
  • 我错过了一些东西
谁知道呢