Hacker News new | past | comments | ask | show | jobs | submit login

You could do it like this:

    const mapNodeList = (...nodeList) => nodeList.map(myFn);
    mapNodeList(...$nodeList)



Or simply [...nodeList].map()


I don't think you can use splats with a NodeList. At least, the TypeScript compiler complains about it.


`[ ...document.body.childNodes ]` is legal. You need to have the `DOM.Iterable` enabled in your compilerOptions.libs` for TypeScript to permit it, though.


Works for me. Splats work for any iterable.


That creates an entire extra list of garbage.


    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...


Doesn’t the compiler optimise it away?


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: