Skip to content

Instantly share code, notes, and snippets.

@navio
Last active August 29, 2015 14:05
Show Gist options
  • Save navio/f357a8f36518f28f4f11 to your computer and use it in GitHub Desktop.
Save navio/f357a8f36518f28f4f11 to your computer and use it in GitHub Desktop.
Observer JS
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