01 function ObserverList(){
02 this.observerList = [];
03 }
04
05 ObserverList.prototype.Add = function( obj ){
06 return this.observerList.push( obj );
07};
08
09 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 i++;
46}
47
48 return pointer;
49};
50
51
52 ObserverList.prototype.RemoveAt = function( index ){
53 if( index === 0 ){
54 this.observerList.shift();
55 }else if( index === this.observerList.length -1 ){
56 this.observerList.pop();
57 }
58};
59
60
61 // Разширение обекта
62 function extend( extension, obj ){
63 for ( var key in extension ){
64 obj[key] = extension[key];
65 }
66}
SqrTT
19.11.13 в 10:20