Note that there are some explanatory texts on larger screens.

plurals
  1. POHow Google Closure EventTarget works?
    text
    copied!<p>I'm hitting an error in advanced compilation mode.</p> <pre><code>Uncaught TypeError: Object #&lt;d&gt; has no method 'attachEvent' </code></pre> <p>After some source map magic I figured that this is thrown from <code>goog.events.listen</code> call, where first argument is my custom object, inheriting <code>goog.events.EventTarget</code>.</p> <p>This is in closures's source</p> <pre><code>goog.events.EventTarget.prototype.addEventListener = function( type, handler, opt_capture, opt_handlerScope) { goog.events.listen(this, type, handler, opt_capture, opt_handlerScope); }; </code></pre> <p>So this function ends up on prototype of my object, along with <code>customEvent_ = true</code>, then in <code>goog.events.listen</code></p> <pre><code>// 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); } </code></pre> <p>(The last line is the one that throws)</p> <p>Shouldn't this end up in stack overflow? Why is it going into <code>else</code> branch if my object inherits <code>addEventListener</code> from <code>EventTarget</code>? In simple compilation mode, everything works fine. How does this work, and why am I getting the error only in advanced compilation mode?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload