0

From Google Maps Utility Library looking at the source of InfoBubble I found that the author creates prototype methods with dot notation, but then at the end of the method definition he reassigns the same proto property with bracket notation.

This should clarify:

/**
 * 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;

Any idea?

4

2 に答える 2

0

私はそれを解決したと思います。

この明らかなナンセンスは、GoogleClosureのコンパイルに関係しているようです。

/**
 * 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、メソッドのプリアンブルブロックにタグがないことを検出することでこれを行うことができます。

多分 :

  • Closureコンパイラは(まだ)それほど賢くはありません。
  • InfoBubbleが作成された時点では、Closureコンパイラはそれほど賢くありませんでした。
  • 何かが足りません。

誰がどちらを知っていますか?

于 2013-09-15T04:31:14.463 に答える
-2

特定のブラウザにバグがない限り、その理由はわかりません。

于 2012-12-05T18:54:55.440 に答える