js下通过prototype扩展实现indexOf的代码_javascript技巧
来源:动视网
责编:小采
时间:2020-11-27 20:56:19
js下通过prototype扩展实现indexOf的代码_javascript技巧
js下通过prototype扩展实现indexOf的代码_javascript技巧: 代码如下: Array.prototype.indexOf = function (str) { for (var i = 0; i if (str == this[i]) { return i; } } return -1; }
导读js下通过prototype扩展实现indexOf的代码_javascript技巧: 代码如下: Array.prototype.indexOf = function (str) { for (var i = 0; i if (str == this[i]) { return i; } } return -1; }

代码如下:
Array.prototype.indexOf = function (str) {
for (var i = 0; i < this.length; i++) {
if (str == this[i]) {
return i;
}
}
return -1;
}
script>
js下通过prototype扩展实现indexOf的代码_javascript技巧
js下通过prototype扩展实现indexOf的代码_javascript技巧: 代码如下: Array.prototype.indexOf = function (str) { for (var i = 0; i if (str == this[i]) { return i; } } return -1; }