Last active
August 29, 2015 14:05
-
-
Save navio/f357a8f36518f28f4f11 to your computer and use it in GitHub Desktop.
Observer JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ObserverList(){ | |
this.observerList = []; | |
} | |
ObserverList.prototype.add = function( obj ){ | |
return this.observerList.push( obj ); | |
}; | |
ObserverList.prototype.pull = function(obj){ | |
return this.observerList.slice(0,1); | |
} | |
ObserverList.prototype.count = function(){ | |
return this.observerList.length; | |
}; | |
ObserverList.prototype.get = function( index ){ | |
if( index > -1 && index < this.observerList.length ){ | |
return this.observerList[ index ]; | |
} | |
}; | |
ObserverList.prototype.indexOf = function( obj, startIndex ){ | |
var i = startIndex; | |
while( i < this.observerList.length ){ | |
if( this.observerList[i] === obj ){ | |
return i; | |
} | |
i++; | |
} | |
return -1; | |
}; | |
ObserverList.prototype.removeAt = function( index ){ | |
this.observerList.splice( index, 1 ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment