Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Implementing a CoffeeScript Feature in Pure JavaScript (github.com/raganwald)
13 points by raganwald on Dec 20, 2012 | hide | past | favorite | 5 comments


This is coming in the next version of EcmaScript. See Rest Parameters: http://wiki.ecmascript.org/doku.php?id=harmony:rest_paramete...

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/


Most useful features in CoffeeScript have been co-opted by ES6 and its proliferation will put pressure on CS to innovate some new features or become much less relevant. The "ideal" JS code near the end of the article almost is valid ES6. The following is valid ES6:

    var leftPartial = (fn, ...args) => function(...remainingArgs){
      return fn.apply(this, args.concat(remainingArgs));
    };
    
Run it in http://benvie.github.com/continuum.


This is really nice, both for showing a useful feature, and also for helping expand my mind on how useful functions which take functions and return another function can be!


> Works like a charm!

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.


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

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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: