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?
divs
is not an instance ofArray
. It is an instance ofNodeList
. It returns the errorObject doesn't support property or method 'slice'
when trying to do it that way. Using.call()
makes it sothis
refers to the correct object. – Jonajonah