高度なコンパイルモードでエラーが発生します。
Uncaught TypeError: Object #<d> has no method 'attachEvent'
ソースマップの魔法の後で、これは呼び出しからスローされることがわかりましたgoog.events.listen
。最初の引数は、を継承するカスタムオブジェクトgoog.events.EventTarget
です。
これはクロージャのソースにあります
goog.events.EventTarget.prototype.addEventListener = function(
type, handler, opt_capture, opt_handlerScope) {
goog.events.listen(this, type, handler, opt_capture, opt_handlerScope);
};
したがって、この関数は、私のオブジェクトのプロトタイプになりますcustomEvent_ = true
。goog.events.listen
// Attach the proxy through the browser's API
if (src.addEventListener) {
if (src == goog.global || !src.customEvent_) {
src.addEventListener(type, proxy, capture);
}
} else {
// The else above used to be else if (src.attachEvent) and then there was
// another else statement that threw an exception warning the developer
// they made a mistake. This resulted in an extra object allocation in IE6
// due to a wrapper object that had to be implemented around the element
// and so was removed.
src.attachEvent(goog.events.getOnString_(type), proxy);
}
(最後の行はスローする行です)
これはスタックオーバーフローで終わるべきではありませんか?オブジェクトがからelse
継承する場合、なぜブランチに入るのですか?単純なコンパイルモードでは、すべてが正常に機能します。これはどのように機能しますか?また、高度なコンパイルモードでのみエラーが発生するのはなぜですか?addEventListener
EventTarget