changed checking if eventhandler storage exists

This commit is contained in:
DennisSchiefer 2012-03-18 12:29:02 +01:00
parent 350cacb2f3
commit 276b023b05

View File

@ -27,14 +27,14 @@ OSRM.extend( OSRM.EventHandler, {
// add listener // add listener
addListener: function(type, listener) { addListener: function(type, listener) {
if( typeof this._listeners[type] == "undefined" ) if( this._listeners[type] == undefined)
this._listeners[type] = []; this._listeners[type] = [];
this._listeners[type].push(listener); this._listeners[type].push(listener);
}, },
//remove event listener //remove event listener
removeListener: function(type, listener) { removeListener: function(type, listener) {
if( this._listeners[type] instanceof Array) { if( this._listeners[type] != undefined) {
for(var i=0; i<this._listeners[type].length; i++) for(var i=0; i<this._listeners[type].length; i++)
if( this._listeners[type][i] == listener) { if( this._listeners[type][i] == listener) {
this._listeners[type].splice(i,1); this._listeners[type].splice(i,1);
@ -53,7 +53,7 @@ OSRM.extend( OSRM.EventHandler, {
if( !event.type ) if( !event.type )
throw new Error("event object missing type property!"); throw new Error("event object missing type property!");
if( this._listeners[event.type] instanceof Array) if( this._listeners[type] != undefined)
for(var listener in this._listeners[event.type]) for(var listener in this._listeners[event.type])
listener.call(this, event); listener.call(this, event);
} }