Comments (9)
Like it alot.
Could also have ruby 2.0 style named arguments? E.g
start_reading(book: "The Jungle Book", page: 0)
Might be more complexity than you're willing to add at this point.
from coffeescript.
I like both ideas. Weepy's can be implemented using objects (The "normal" way in plain Javascript).
from coffeescript.
I like weepy's idea too, -- it's a nice shorthand in Ruby, and it would be nice to have it here. The only twist is that it's already valid CoffeeScript syntax.
start_reading(book: 'The Jungle Book', page: 0)
Compiles into:
var book, page;
start_reading(book = 'The Jungle Book', page = 0);
So we might need to keep the brackets wrapper just to be specific about what you mean.
from coffeescript.
how does ruby manage it ?
from coffeescript.
Well, in Ruby, assignment uses =
, not :
, so it's not ambiguous. I don't really mind the brackets though -- it's nice to know that you're passing an arguments object and not named arguments -- they don't work the same way within the method.
from coffeescript.
Alright -- splats in function definitions are now on master. Kick the tires if you'd like. This:
party: host, *guests =>
guests.each(guest => host.danceWith(guest))
Compiles into:
var party;
party = function party(host) {
var guests;
guests = Array.prototype.slice.call(arguments, 1);
return guests.each(function(guest) {
return host.danceWith(guest);
});
};
from coffeescript.
And splats are now available as arguments to function calls. Calling the function defined above:
party(me, *friends, *relatives)
Compiles into:
party.apply(this, [me].concat(friends).concat(relatives));
from coffeescript.
Going to leave default parameters out for the time being, because they would significantly complicate the grammar and have the potential to look really confusing within function assignments. If anyone has a proposal for what default parameters should look like, feel free to open a new ticket. Closing this one.
(If you'd like to have default arguments now, you can use the ||=
operator.)
from coffeescript.
New ticket: http://github.com/jashkenas/coffee-script/issues#issue/92
discussing default parameters.
Problem with using ||= is that it is bug-prone.
Horse: name, speed =>
this.name: name
this.speed: speed || 45
deadHorse = new Horse("Gluey", 0);
"This dead horse has a speed of " + deadHorse.speed + "!"
# ... 45!
from coffeescript.
Related Issues (20)
- Unnecessary `splice` ref added for Array destructuring with rest element not in last position HOT 4
- Bug: Re-ordered nested non-end BindingRestElement doesn't get transpiled HOT 1
- CoffeeScript is fantastic, please donβt give it up HOT 1
- How to imitate `let` behavior in loops? HOT 5
- Proposal: Alternative file extension HOT 1
- Bug: Excessive variable and shallow copy for leading or middle rest parameter
- Proposal: Introduce `let` statement. HOT 6
- Proposal: Document Existential Operator Assignment
- Site issue: code blocks twitch on hover HOT 2
- Proposal: cake command should support ES6 modules HOT 2
- Need help understanding class member meanings HOT 1
- CLI `npm` `scripts` and input `.coffee` file/s as last argument conflicting with `--watch` HOT 2
- Bug: wrong code is transpiled for function call without parentheses HOT 2
- Proposal: Add end word to close method or class HOT 2
- Bug: Invalid indentation allowed after `do`
- Bug: Remove checkShebangLine multi arguments check HOT 1
- feature_request(html): backend CoffeeScript compilation inside HTML files HOT 3
- Bug: yield cannot be used in do -> expressions reliably? HOT 5
- [not an issue] An embeddable playground for CoffeeScript HOT 1
- Please help HOT 2
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 coffeescript.