We know that the argument inside the function is actually an object stored as an array, but it's not an array.
If we are going to convert it to an array, you can call Array.prototype.slice () this method
Analyze This method:
array.prototype: Array is actually a class name, but the method inside the call class can only be called through an instance object of the class, so here is a array.prototype called by its own prototype object.
Next is slice (): This is an array class inside a method function is to intercept a part of the array content, it receives two parameters slice (' array subscript start position ', ' array subscript end position ')
Call () method: Put a method into another execution environment, this method also has two parameters called (' Execution Environment ', ' to invoke the method of the parameter (can be ignored) ')
Well, look at the example:
functionConverttoarray (nodes) {vararr =NULL; //compatible with IE Try{arr= Array.prototype.slice.call (nodes,0); //because slice is a method of the array class //and the passed in parameter is an array of Dom objects //so the method of array class is put into this object by the call method to execute //The second argument to call is to pass in a parameter to the called method //here, 0 means starting at index 0.}Catch(ex) {arr=NewArray (); for(vari = 0; i < nodes.length; i++) {Arr.push (nodes[i]); } } returnarr; }
This is an example of elevation: passing a function into an ChildNodes instance object, and then converting the object of this child element model to an array
The ChildNodes property contains a NodeList object, NodeList is a class array object that holds an ordered set of nodes that can be accessed by location
To be compatible with ie<9 subclasses are COM objects we cannot use such objects as JScript objects, so in catch we iterate through the NodeList object inside the ChildNodes property and instantiate an array Save these traversed node elements
"Notes" JS Array.prototype.slice.call (arguments) transforms the arguments of a function into an insight into an array method