Array.js
[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      * Checks whether or not the specified object exists in the array.
17      * @param {Object} o The object to check for
18      * @return {Number} The index of o in the array (or -1 if it is not found)
19      */
20     indexOf : function(o){
21        for (var i = 0, len = this.length; i < len; i++){
22               if(this[i] == o) return i;
23        }
24            return -1;
25     },
26
27     /**
28      * Removes the specified object from the array.  If the object is not found nothing happens.
29      * @param {Object} o The object to remove
30      */
31     remove : function(o){
32        var index = this.indexOf(o);
33        if(index != -1){
34            this.splice(index, 1);
35        }
36     },
37     /**
38      * Map (JS 1.6 compatibility)
39      * @param {Function} function  to call
40      */
41     map : function(fun /*, thisp*/)
42     {
43         var len = this.length >>> 0;
44         if (typeof fun != "function")
45             throw new TypeError();
46
47         var res = new Array(len);
48         var thisp = arguments[1];
49         for (var i = 0; i < len; i++)
50         {
51             if (i in this)
52                 res[i] = fun.call(thisp, this[i], i, this);
53         }
54
55         return res;
56     }
57     
58 });
59
60
61
62 if (!Array.prototype.map)
63 {
64   Array.prototype.
65 }