Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Any object can become iterable by adding Symbol.iterator, and destructuring should work for them. You can even patch Symbol.iterator on arrays itself, and the VM has to cope:

    > Array.prototype[Symbol.iterator] = function*() { yield 1; yield 2; yield 3; }
    > [...[4, 5, 6]]
    [1, 2, 3]
The terrible performance of the iterator protocol was discussed and ignored at the time, by saying that escape analysis would solve it [0]. Nearly 10 years later, and escape analysis has still not solved it. It's extremely GC-hungry and still sucks. It's just a bad spec, designed by people who are not performance-conscious.

It might make sense for engines to specialize destructuring assignment and splicing of Arrays to remove their iterator protocol overhead (if the user hasn't patched Symbol.iterator) but that's a whole other can of worms.

[0] https://esdiscuss.org/topic/performance-of-iterator-next-as-...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: