Guest User

Untitled

a guest
Nov 17th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ObserverList(){
  2.   this.observerList = [];
  3. }
  4.  
  5. ObserverList.prototype.Add = function( obj ){
  6.   return this.observerList.push( obj );
  7. };
  8.  
  9. ObserverList.prototype.Empty = function(){
  10.   this.observerList = [];
  11. };
  12.  
  13. ObserverList.prototype.Count = function(){
  14.   return this.observerList.length;
  15. };
  16.  
  17.  
  18. ObserverList.prototype.Get = function( index ){
  19.   if( index > -1 && index < this.observerList.length ){
  20.     return this.observerList[ index ];
  21.   }
  22. };
  23.  
  24. ObserverList.prototype.Insert = function( obj, index ){
  25.   var pointer = -1;
  26.  
  27.   if( index === 0 ){
  28.     this.observerList.unshift( obj );
  29.     pointer = index;
  30.   }else if( index === this.observerList.length ){
  31.     this.observerList.push( obj );
  32.     pointer = index;
  33.   }
  34.  
  35.   return pointer;
  36. };
  37.  
  38. ObserverList.prototype.IndexOf = function( obj, startIndex ){
  39.   var i = startIndex, pointer = -1;
  40.  
  41.   while( i < this.observerList.length ){
  42.     if( this.observerList[i] === obj ){
  43.       pointer = i;
  44.     }
  45.   }
  46.  
  47.   return pointer;
  48. };
  49.  
  50.  
  51. ObserverList.prototype.RemoveAt = function( index ){
  52.   if( index === 0 ){
  53.     this.observerList.shift();
  54.   }else if( index === this.observerList.length -1 ){
  55.     this.observerList.pop();
  56.   }
  57. };
  58.  
  59.  
  60. // Extend an object with an extension
  61. function extend( obj, extension ){
  62.   for ( var key in obj ){
  63.     extension[key] = obj[key];
  64.   }
  65. }
Add Comment
Please, Sign In to add comment