It is my understanding that IE8 has access to the Array.prototype.slice method. Yet when I try to call it to turn a NodeList into an array, it gives me the error Array.prototype.slice: 'this' is not a JavaScript object. You can check it out here, or look at my code here:
HTML
<div id="test">Test</div>
JavaScript
var divs = document.getElementsByTagName('div');
divs = Array.prototype.slice.call(divs);
console.log(divs);
What’s going on here?
Update: A
NodeListcan be treated as an array in some ways – you don’t actually have to do anything special with it before you can loop over it, for example:This will create an array with all of the nodes that matched when you ran
document.getElementsByTagName()See this question for a full explanation of why
sliceworks with aNodeListin some browsers but not others, but it boils down this this sentence from the specification: