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