Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
nicoburns
on July 9, 2021
|
parent
|
context
|
favorite
| on:
How JavaScript Works: deep dive into call, apply, ...
You could do it like this:
const mapNodeList = (...nodeList) => nodeList.map(myFn); mapNodeList(...$nodeList)
kevincox
on July 9, 2021
|
next
[–]
Or simply [...nodeList].map()
moron4hire
on July 10, 2021
|
parent
|
next
[–]
I don't think you can use splats with a NodeList. At least, the TypeScript compiler complains about it.
webstrand
on July 10, 2021
|
root
|
parent
|
next
[–]
`[ ...document.body.childNodes ]` is legal. You need to have the `DOM.Iterable` enabled in your compilerOptions.libs` for TypeScript to permit it, though.
edflsafoiewq
on July 10, 2021
|
root
|
parent
|
prev
|
next
[–]
Works for me. Splats work for any iterable.
hajile
on July 9, 2021
|
prev
[–]
That creates an entire extra list of garbage.
lhorie
on July 9, 2021
|
parent
|
next
[–]
const mapNodeList = (...nodeList) => nodeList.map(myFn); mapNodeList(...$nodeList)
Garbage collection really isn't the biggest of concerns here considering this code is susceptible to a stack overflow...
chrisseaton
on July 9, 2021
|
parent
|
prev
[–]
Doesn’t the compiler optimise it away?
hajile
on July 9, 2021
|
root
|
parent
[–]
Those aren't the same types. One is a DOM array and the other is a JS array. They don't share the same constructor or the same prototype chain.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: