3 ms·
> [].slice.call on the result of querySelectorAll turns that NodeMap (NodeList? I forget) into a proper array, on which all of the language's sequence manipulat
by BinaryIdiot 10y ago
> [].slice.call on the result of querySelectorAll turns that NodeMap (NodeList? I forget) into a proper array, on which all of the language's sequence manipulatory methods work as they should.
While true it's important to remember this creates a new, shallow array copy. It's not something you'd want to call often.
Also it may be better to use Array.prototype.slice.call instead to avoid the extra, empty array instance your shortcut creates. How much better is likely insignificant, however; it's mostly a personal preference of mine :)
> I don't know why that method doesn't just return an array to begin with, but this is how you get one from it.
I believe this answers that pretty well (I've had the same, frustrating question in the past): http://stackoverflow.com/a/2601582/242023 http://stackoverflow.com/a/2601582/242023
- throwanem 10y agoThat's a fair point about garbage creation; I wouldn't do that in a tight inner loop, either. And now I know why that method doesn't just return an array to begin with. Thanks!