> why does `...` use iterators??
If you couldn't use the iterator protocol, generators in particular would be a lot less powerful
If you couldn't use the iterator protocol, generators in particular would be a lot less powerful
[a, b, ...rest] = array
is implemented like this: a = array[0]
b = array[1]
rest = array[2...]
When instead it is a giant performance footgun to the point where it should only be used outside of performance critical code.EDIT "next -> rest"
array.slice(2)
Fundamentally, it's the same thing that impedes most optimizations: there are hundreds of different patterns we could optimize, it takes a fair bit of thought to get it right, and we have finite resources, so we have to pick and choose. This particular pattern turns out to be idiomatic in a lot of React code, which is why we're looking at it now. (Or so people tell me; most JS I write is gross little testcases.)