1 /*
  2  * concat()/join()/pop()/push()/reverse()/shift()
  3  * slice()/sort()/splice()/toSource()/toLocaleString()
  4  * unshift()/
  5 */
  6 
  7 /*扩展获取长度方法*/
  8 Array.prototype.Length = function() {
  9         return this.length;
 10 }
 11 
 12 /*扩展数组指定位置插入方法*/
 13 Array.prototype.ListInsert = function(value,position){
 14     /*
 15      * 插入过程中,先水平移动再插入 
 16      */
 17         var len = this.length-1;                //记录数组长度,为获取最后一位数据做准备
 18         var mv_len = this.length - position;    //水平移动位移
 19         var in_pos = position;                    //插入位置
 20 
 21         //判断插入的是number/object/array
 22         //function,string也具有length属性
 23         if(value.length === undefined || typeof(value) === 'string' || typeof(value) === 'function'){        
 24             var in_len = 1;
 25         }else{
 26             var in_len = value.length;            //需要插入元素的长度
 27         }
 28 
 29         //第一次循环水平移位
 30         for(var i=mv_len; i>0; i--){
 31             this[len+in_len] = this[len--];
 32         }
 33 
 34         //第二次循环插入数据
 35         for(var i=0; i<in_len; i++){
 36             //对于处理object/string/function这类的数据直接插入
 37             if(value.length === undefined || typeof(value) === 'string' || typeof(value) === 'function'){
 38                 this[in_pos] = value;
 39                 continue;
 40             }
 41             this[in_pos++] = value[i];
 42         }
 43         return this;
 44 }
 45 
 46 /*扩展元素获取方法*/
 47 Array.prototype.getElem = function(indx) {
 48     if(!isNaN(indx))        //是否是可计算的表达式
 49         return this[indx];
 50     return false;
 51 }
 52 
 53 /*扩展的清空数组方法*/
 54 Array.prototype.ListEmpty = function() {
 55     //方法1
 56     //this.splice(0,this.length);
 57     //方法2
 58     this.length = 0;
 59     //方法3 形如: a = []
 60     return this;
 61 }
 62 
 63 /*扩展的元素位置方法(第一个匹配的,未找到返回-1)*/
 64 Array.prototype.LocateElem = function(value) {
 65     for(var i=0; i<this.length; i++){
 66         if(value === this[i])
 67             return i;
 68     }
 69     return -1;
 70 }
 71 
 72 /*扩展的找前驱方法,不能为第一位元素*/
 73 Array.prototype.PriorElem = function(cur_e) {
 74     if(this.LocateElem(cur_e) <= 0)
 75         return -1;
 76     return this[this.LocateElem(cur_e)-1]
 77 }
 78 
 79 /*扩展的找后继方法,不能为最后一个元素*/
 80 Array.prototype.NextElem = function(cur_e) {
 81     if(this.LocateElem(cur_e) >= this.length)
 82         return -1;
 83     return this[this.LocateElem(cur_e)+1]
 84 }
 85 
 86 /*扩展的数组元素删除方法*/
 87 Array.prototype.ListDelete = function(indx) {
 88     for(var i=indx; i<this.length; i++){
 89         this[i] = this[i+1];
 90     }
 91     this.length--;
 92     return this;
 93 }
 94 
 95 /*扩展的遍历链表方法*/
 96 Array.prototype.ListTraverse = function() {
 97     //return this.toString();
 98     return this.valueOf();
 99 }