Home >Web Front-end >HTML Tutorial >Explain the meaning of the statement_html/css_WEB-ITnose
Array.prototype.i = Array.prototype.indexOf ||
function(value){
for (var i = this.length; i-- && this[i]!== value;) {}
return i;
};
What does this passage mean? ? Please explain.
Especially
Array.prototype.indexOf ||
function(value)
I don’t understand this!
The indexOf in Array.prototype.indexOf is the method implemented by the class Array
which means:
If this method is implemented, this Array.prototype.i = Array.prototype.indexOf
That is, i and indexOf agree
If this method is not implemented, use the following function for the extension method i in Array Implement
Array.prototype.i = Array.prototype.indexOf || function(value) { for (var i = this.length; i-- && this[i] !== value;) {} //这里有点问题, return i;语句应该是在这个for循环体内的 return i;};//等价于if (Array.prototype.indexOf != false) Array.prototype.i;else Array.prototype.i = function(value) { for (var i = this.length; i-- && this[i] !== value;) { return i; }}
such as
. b assignment, if a has a value, then assign the value of a to b, if a has no value, then assign 4 to b
var a; var b = a || 4; alert(b)
JScript code
Array.prototype.i = Array.prototype.indexOf || function(value) {
for (var i = this.length; i-- && ; this[i] !== value;) {} //There is a problem here, the return i; statement should be in the body of this for loop
return i...
like this , thank you all!