Guest User

Untitled

a guest
Oct 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. class ObserverList {
  2. constructor() {
  3. this.observerList = [];
  4. }
  5.  
  6. add(obj) {
  7. return this.observerList.push(obj);
  8. }
  9.  
  10. count() {
  11. return this.observerList.length;
  12. }
  13.  
  14. get(index) {
  15. if( index > -1 && index < this.observerList.length ){
  16. return this.observerList[ index ];
  17. }
  18. }
  19.  
  20. indexOf(obj, startIndex) {
  21. let i = startIndex;
  22.  
  23. while( i < this.observerList.length ){
  24. if( this.observerList[i] === obj ){
  25. return i;
  26. }
  27. i++;
  28. }
  29.  
  30. return -1;
  31. }
  32.  
  33. removeAt(index) {
  34. this.observerList.splice( index, 1 );
  35. }
  36. }
Add Comment
Please, Sign In to add comment