Comments (4)
Thanks. I tried to nail this quick the other day since I only had a minute, and accidentally did params instead of args. Revising now.
from ecmascript-sublime.
Thanks! Incidentally, this reminded me how irritated I am that a leading rest operation is illegal in the first place. Don't suppose you've got any insight on why this is the case?
from ecmascript-sublime.
I bet there are ES Discuss records about that. Perhaps it would create some hidden complexity. Superficially, permitting a "rightward" mapping is not ambiguous:
function poop(...rest, last) {}
function poop(...rest, penultimate, last) {}
The first thing I can think of is that it does require some new grammar, because this, along with any other parameter declaration with two rests, is nonsensical:
function poop(...wat, ...no) {}
On the other hand, this is actually unambiguous:
function poop(first, ...middle, last) {}
So they could have written the grammar such that any given parameter declaration would contain zero or one rest parameters. I don't think this would have required any hoop jumping, actually -- no cover grammars or anything like that -- so I doubt grammatical complexity was the issue.
So perhaps it has something to do with how function parameters are implemented internally -- maybe it would be somehow disruptive that, if non-terminal rests were permitted, _non-_rest parameters would no longer have specific indices. But I'm just guessing here; for all I know, nobody brought it up? I'm pretty clueless about the internal mechanics for outfitting functions.
from ecmascript-sublime.
Other thoughts: In your own code, you can implement a simple util for supporting right-to-left rest-params. (More complex forms wouldn't be so easy to represent, though):
const reversedRest = fn => {
const ln = fn.length;
return (...args) => {
const rest = args.slice(0, -ln);
const named = args.reverse().slice(0, ln);
return fn(...named, ...rest);
};
}
const example = reversedRest((tail, ...rest) =>
`the tail is "${ tail }"; there are ${ rest.length } members prior (${ rest })`
);
console.log(example('a', 'b', 'c', 'd'));
On Babel REPL
from ecmascript-sublime.
Related Issues (20)
- a way of setting the default syntax for a template tag HOT 2
- Add support for graphql nested syntax HOT 5
- Comma background in destructuring assignments HOT 5
- Error loading colour scheme Packages/Ecmascript Syntax/excelsior.tmTheme HOT 4
- Update repository description HOT 3
- Add support for pug nested syntax HOT 5
- Build process does not work on Windows HOT 1
- Pipeline operator
- styled jsx has no css autocomplete and emmet does not work HOT 5
- Use a package setting to override the block comment directive syntax HOT 6
- Add support for interpolated attribute values in HTML / HTML-like template tags without quotation marks HOT 7
- AE identifiers prefixed with reserved words followed by `$`
- Digits after binary/octal HOT 4
- Async iterable inline literal object
- Associating Ecmascript with source.js ? HOT 4
- Update README ? HOT 1
- Symbols are not indexed in embedded syntax HOT 1
- Add DOM support for built-in color schemes HOT 5
- Turn off Safe Mode/Prefer Ecmascript standard mode. HOT 2
- LSP integration HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ecmascript-sublime.