-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Array.from instead of [].slice #963
Comments
If we decide to output ES6, we can use spread here, spread can be used with any iterables(including generators) like splat-in-array = [a, ...b, c, ...gen!]
splat-in-object = {a, ...b, c, ...d}
call-with-splat-parameters = fn a, ...b, c, ...d var splatInArray, splatInObject, callWithSplatParameters
splatInArray = [a, ...b, c, ...gen()];
splatInObject = {
a,
...b,
c,
...d
};
callWithSplatParameters = fn(a, ...b, c, ...d); |
Targeting ES6 has been discussed elsewhere, I believe, and if it's worth doing, it's worth doing in the context of a broader review of the backend, such as #862. In the meantime, this can certainly be addressed in an ES3-compatible way, which is my intent. |
Prior to this commit, [].slice was used to turn array-like things into arrays when needed for splats in array literals. This commit uses Array.from instead, when available at runtime, and falls back to slice when not. This allows a wider range of iterables to be used as splats, on the platforms that support them (platforms missing Array.from will also be missing more exotic iterables). Fix gkz#963.
@rhendric congrats on the badge! |
Prior to this commit, [].slice was used to turn array-like things into arrays when needed for splats in array literals. This commit uses Array.from instead, when available at runtime, and falls back to slice when not. This allows a wider range of iterables to be used as splats, on the platforms that support them (platforms missing Array.from will also be missing more exotic iterables). Fix #963.
thanks 8) |
Example code
Expected JavaScript
Current JavaScript
The text was updated successfully, but these errors were encountered: