js prototype原形对象用处

js prototype原型对象用处Array.prototype.pushEx function(obj){var a truefor (var i 0 i thi

js prototype原型对象用处

Array.prototype.pushEx = function(obj){  var a = true;  for (var i = 0; i < this.length; i++) {    if (this[i]== obj) {       this[i] = obj;       a =false;       break;    }  }  if(a){    this.push(obj);   }  return this.length;}var test1 = new Array();test1.pushEx("bb");test1.pushEx("bb");test1.pushEx("dd");alert(test1) //bb,dd