Reputation: 534
I need to convert a NodeList
object to an array - in this case, a list of <div>
elements, as I need to use the map()
and filter()
methods to refine it.
Unfortunately in Firefox (I tested both 3.6 and 4) the method I'm using throws the following error:
Error: setting a property that only has a getter
The following code is a condensed version of line in question.
trackList = [].splice.call(videoElement.querySelectorAll("div"),0);
This works fine in Chrome and Safari. It doesn't appear to be related to the querySelectAll
method as the same issue occurs regardless of how the NodeList
is obtained (e.g. with document.getElementsByTagName("div")
.)
The issue appears to lie with the call()
method itself - given a preexisting NodeList
and reference to the Array.prototype.slice
method, the following will still fail:
sliceMethod.call(myNodeList,0);
Needless to say, I'm stumped - any assistance or advice would be greatly appreciated.
Update
This turned out to be a typographical error - slice instead of splice was intended.
Upvotes: 2
Views: 985
Reputation: 22126
I think the problem is not with call
but with the NodeList. NodeLists are (I think always) live, meaning that if a new div is added, it automatically becomes part of the NodeList, or if it is removed from the document, it is also removed from the NodeList, etc. Thus it doesn't make sense to take anything out of the NodeList, which is what splice
does. I think probably you meant to use slice
instead.
Upvotes: 1