学习电脑,计算机系统故障维护,电脑技术,电脑知识学习-就上第二电脑网
当前位置: 首页 > 网络编程 > JavaScript

原生js怎么删除classjs Array对象的扩展函数代码

 更新时间: 2019-07-06 15:43:07   作者:第二电脑网   来源:第二电脑网   浏览数:897   我要评论

使用 代码如下:<scipt laguage=javascipt>va isNumeic = fuctio(x) {   // etus tue if x is umeic ad false if it is ot.   va RegExp = /^(-)?(\d*

//分开添加,关键字shallow copy,如果遇到数组,复制数组中的元素
Array.prototype.concat = function(){
 var i=0;
 while(i<arguments.length){
  if(typeof arguments[i] === 'object'&&typeof arguments[i].splice ==='function' &&!arguments[i].propertyIsEnumerable('length')){
  // NOT SHALLOW COPY BELOW
  // Array.prototype.concat.apply(this,arguments[i++]);
   var j=0;
   while(j<arguments[i].length) this.splice(this.length,0,arguments[i][j++]);
   i++;
  } else{
   this[this.length]=arguments[i++];
  }
 }
 return this;
}

Array.prototype.join = function(separator){
 var i=0,str="";
 while(i<this.length) str+=this[i++]+separator;
 return str;
}

Array.prototype.pop = function() { return this.splice(this.length-1,1)[0];}

Array.prototype.push = function(){
 Array.prototype.splice.apply(this,
  [this.length,0].concat(Array.prototype.slice.apply(arguments))); //这里没有直接处理参数,而是复制了一下
 return this.length;
}
Array.prototype.reverse = function(){
 for(var i=0;i<this.length/2;i++){
  var temp = this[i];
  this[i]= this[this.length-1-i];
  this[this.length-1-i] = temp;
 }
 return this;
}
Array.prototype.slice = function(start, end){
 var len =this.length;
 start=start<0?start+=len:start?start:0;
 end =end<0?end+=len:end>len?len:end?end:len;

 var i=start;
 var res = [];
 while(i<end){
  res.push(this[i++]);
 }
 return res; 
}
//arr.unshift(ele1,ele2,ele3....)
Array.prototype.unshift =function(){
 Array.prototype.splice.apply(this,[0,0].concat(Array.prototype.slice.apply(this,arguments)));
}


更多:原生js怎么删除classjs Array对象的扩展函数代码
https://www.002pc.comhttps://www.002pc.com/javascript/995.html

你可能感兴趣的js,Array,代码,函数,扩展,对象

关于我们 - 广告合作 - 联系我们 - 免责声明 - 网站地图 - 投诉建议 - 在线投稿

  浙ICP备140365454号

©CopyRight 2008-2020 002pc.COM Inc All Rights Reserved. 第二电脑网 版权所有 联系QQ:282523118