There are three types of class array objects:
1.arguments
2. Elements Collection
3. Node Collection
var olis = document.getelementbytagname ("div");
Console.dir (Olis); An instance of the->htmlcollection element collection class, which is also a collection of class arrays
var olis = document.getelementbyname ("div");
Console.dir (Olis); An instance of the->nodelist node collection class, which is also a collection of class arrays
Class array conversions to arrays:
-"Standard Browser method:
var ary = [].slice.call (Olis)
Problem: Busy in Ie6-8 browser does not support the slice implementation of the borrowed array to convert an array of elements of an element collection to an error (element collection and node collection are not supported, but arguments is supported without any compatibility issues)
-"non-standard method; ie6-8
for (var i = 0;i<olis.length;i++) {
Ary[ary.length] = Olis[i]
}
Complementary points of knowledge:
1. Browser exception information capture:
We use Try,catch in JS to capture the exception information of the browser
Console.log (num)//Direct error, in JS, the bank error, the following code is not executed
Console.log ("OK")
1) If the exception information is captured with Try,catch, the following code is not affected to continue execution. If the code in the try executes an error, the code in the catch is executed by default
Trycatch(e) {// parameter must be written, usually named E console.log ("error") Console.log ( e.message,111111)//can collect the cause of the current Code error} console.log ("OK")
2)
Requirements: Sometimes you want to capture the error message, and you don't want the following code to continue
Try { // JS code Catch (e) { // If code error executes code in catch
Manually throwing an error message, terminating code execution
throw new Error ("The current network is busy, please try again later")
New Referenceerror//-Reference error message
New TypeError//Type Error
New Rangeerror//Range error
finally { // do not use: Execute code in Finally, regardless of whether the code in the try is an error or not
A complete array of classes, a way to convert to arrays
varUtils = { //implements transforming an array of classes into arrays, using Try,catch to detect compatibilitylisttoarray:function (likeary) {varary = []; Try{ary=Array.prototype.slice.call (likeary); } Catch(e) { for(vari =0; i<likeary.length;i++) {Ary[ary.length]=Likeary[i]}} returnary; }}
26. Class array conversions to arrays