If I create a new "Foo" and use the "addEventListener" method on it, it affects Foo's prototype and all new instances of Foo.
Simple example: http://jsfiddle.net/TYkF2/
function Foo() { }
Foo.prototype = {
_evt: { open: [], close: [] },
addEventListener: function(name, handler) {
if (name in this._evt) {
if (!(this._evt[name].indexOf(handler) > -1)) {
this._evt[name][this._evt[name].length] = handler;
}
}
},
dispatchEvent: function(name, data) {
data = data || {};
if (name in this._evt) {
for (var i = 0; i < this._evt[eventName].length; i++) {
this._evt[name][i].call(this, data);
}
}
}
};
var a = new Foo();
a.addEventListener("open", function() { alert("Hey!"); });
a.dispatchEvent("open");
var b = new Foo();
b.dispatchEvent("open"); // alerts Hey
alert(Foo.prototype._evt.open); //shows a's event handler