可以用prototype 属性为任何已有的类定义新方法。

 

例:(判断某项在数组中的位置)

Array.prototype.indexof = function (vItem) {
for (var i=0; i < this.length; i++) {
if (vItem == this[i]) {
return ++i;
}
}


}

var aDream = new Array ("Health","Happy","Freedom");
alert(aDream.indexof("Freedom"));

//弹出3

相关文章:

  • 2021-07-11
  • 2021-05-27
  • 2022-02-19
  • 2021-06-12
  • 2022-03-02
  • 2021-10-06
  • 2021-06-30
猜你喜欢
  • 2022-12-23
  • 2022-02-12
  • 2022-02-11
  • 2022-12-23
  • 2021-07-15
  • 2022-01-01
  • 2022-12-23
相关资源
相似解决方案