Implementing a CoffeeScript Feature in Pure JavaScript
github.com
github.com
If you're adventurous or just OK with the idea of using transpilers/precompilers (which you would be if you like CoffeeScript), you can use rest parameters with Traceur [1] or TypeScript [2].
[1] http://code.google.com/p/traceur-compiler/ [2] http://www.typescriptlang.org/
var leftPartial = (fn, ...args) => function(...remainingArgs){
return fn.apply(this, args.concat(remainingArgs));
};
Run it in http://benvie.github.com/continuum.but is ugly. When a feature is part of a language , you dont need to look at the source code of the language to understand how to use it, nor have to import yet another script to make it work.
WHy do you have to look at source code? If I tell you that the Underscore library includes a function called "once" that does such-and-such, you can just use "once," correct?
Same with "ellipses." You don't have to look at the source code if you don't want to.
import yet another script to make it work
Ah, this is a deep philosophical question, well worth consideration.
One philosophy is to have a language that does everything and has extensive official libraries. Java went down this road under Sun's stewardship. The other philosophy is to make the language smaller but powerful enough that people could invent their own stuff and let "the marketplace" decide.
JavaScript is mostly going down this road. Things like "let" and "=>" are being added to the language, but at a fairly slow pace because the language does support creating your own idioms to accomplish the same things, so making it part of the syntax waits until there is an overwhelming mass of programmers who are familiar with the idea.