-
Notifications
You must be signed in to change notification settings - Fork 50k
Closed
Description
I'm getting this error in the console when certain components are removed from the DOM. It's calling the method below, which assumes that target is not null and tries to access addEventListener of null object. Should it be checking if (target && target.addEventListener) {...} instead? Are components being removed in an incorrect way that would cause this to happen?
/**
* Upstream version of event listener. Does not take into account specific
* nature of platform.
*/
var EventListener = {
/**
* Listen to DOM events during the bubble phase.
*
* @param {DOMEventTarget} target DOM element to register listener on.
* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
* @param {function} callback Callback function.
* @return {object} Object with a `remove` method.
*/
listen: function (target, eventType, callback) { // target = null, eventType = "click", callback = emptyFunction()
if (target.addEventListener) {
target.addEventListener(eventType, callback, false);
return {
remove: function () {
target.removeEventListener(eventType, callback, false);
}
};
} else if (target.attachEvent) {
target.attachEvent('on' + eventType, callback);
return {
remove: function () {
target.detachEvent('on' + eventType, callback);
}
};
}
}
Metadata
Metadata
Assignees
Labels
No labels