fix attribute
[roojs1] / Array.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11  /**
12  * @class Array
13  */
14 Roo.applyIf(Array.prototype, {
15     /**
16      * 
17      * Checks whether or not the specified object exists in the array.
18      * @param {Object} o The object to check for
19      * @return {Number} The index of o in the array (or -1 if it is not found)
20      */
21     indexOf : function(o){
22        for (var i = 0, len = this.length; i < len; i++){
23               if(this[i] == o) { return i; }
24        }
25            return -1;
26     },
27
28     /**
29      * Removes the specified object from the array.  If the object is not found nothing happens.
30      * @param {Object} o The object to remove
31      */
32     remove : function(o){
33        var index = this.indexOf(o);
34        if(index != -1){
35            this.splice(index, 1);
36        }
37     },
38     /**
39      * Map (JS 1.6 compatibility)
40      * @param {Function} function  to call
41      */
42     map : function(fun )
43     {
44         var len = this.length >>> 0;
45         if (typeof fun != "function") {
46             throw new TypeError();
47         }
48         var res = new Array(len);
49         var thisp = arguments[1];
50         for (var i = 0; i < len; i++)
51         {
52             if (i in this) {
53                 res[i] = fun.call(thisp, this[i], i, this);
54             }
55         }
56
57         return res;
58     },
59     /**
60      * equals
61      * @param {Array} o The array to compare to
62      * @returns {Boolean} true if the same
63      */
64     equals : function(b)
65     {
66             // https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript
67         if (this === b) {
68             return true;
69         }
70         if (b == null) {
71             return false;
72         }
73         if (this.length !== b.length) {
74             return false;
75         }
76           
77         // sort?? a.sort().equals(b.sort());
78           
79         for (var i = 0; i < this.length; ++i) {
80             if (this[i] !== b[i]) {
81             return false;
82             }
83         }
84         return true;
85     } 
86     
87     
88     
89     
90 });
91
92 Roo.applyIf(Array, {
93  /**
94      * from
95      * @static
96      * @param {Array} o Or Array like object (eg. nodelist)
97      * @returns {Array} 
98      */
99     from : function(o)
100     {
101         var ret= [];
102     
103         for (var i =0; i < o.length; i++) { 
104             ret[i] = o[i];
105         }
106         return ret;
107       
108     }
109 });