Re:How JavaScript Works: deep dive into call, apply, and bind
by nicoburns on Friday July 09, 2021 @06:31PM
(#27789252)
You could do it like this:
[ Parent
| on HN ]
Re:How JavaScript Works: deep dive into call, apply, and bind
by kevincox on Friday July 09, 2021 @07:06PM
(#27789524)
Or simply [...nodeList].map()
Re:How JavaScript Works: deep dive into call, apply, and bind
by moron4hire on Friday July 09, 2021 @08:13PM
(#27789883)
I don't think you can use splats with a NodeList. At least, the TypeScript compiler complains about it.
Re:How JavaScript Works: deep dive into call, apply, and bind
by webstrand on Friday July 09, 2021 @10:53PM
(#27790748)
`[ ...document.body.childNodes ]` is legal. You need to have the `DOM.Iterable` enabled in your compilerOptions.libs` for TypeScript to permit it, though.
Re:How JavaScript Works: deep dive into call, apply, and bind
by edflsafoiewq on Friday July 09, 2021 @09:37PM
(#27790374)
Works for me. Splats work for any iterable.
Re:How JavaScript Works: deep dive into call, apply, and bind
by hajile on Friday July 09, 2021 @06:36PM
(#27789287)
That creates an entire extra list of garbage.
Re:How JavaScript Works: deep dive into call, apply, and bind
by lhorie on Friday July 09, 2021 @07:28PM
(#27789635)
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...
Re:How JavaScript Works: deep dive into call, apply, and bind
by chrisseaton on Friday July 09, 2021 @06:42PM
(#27789337)
Doesn’t the compiler optimise it away?