35 ms·
You can get modules right now, in every browser, with CoffeeScript. It compiles nicely to standard JS: http://coffeescript.org http://coffeescript.org
by TrevorBurnham 16y ago
You can get modules right now, in every browser, with CoffeeScript. It compiles nicely to standard JS:
http://coffeescript.org http://coffeescript.org
- endtime 16y agoI'm a big fan of CS, but I wasn't aware it has module support. Are you talking about the class system?
- TrevorBurnham 16y agoSorry, I should've been clearer: I meant that CoffeeScript gives you the safety benefits of modules, just by breaking your code into separate .coffee files (unless you use '--no-wrap'), since variables aren't shared unless explicitly exported.
- jashkenas 16y agoCoffeeScript does many things at the language level, but modules is not one of them.
- endtime 16y agoMaybe in 0.8 or 0.9, Jeremy? ;-) It could "solve" the "problem" of wrapping compiled code in anonymous functions and having to attach exports to `window`.
- jashkenas 16y agoAh, but all of your compiled code is already wrapped in a safety function. (perhaps that's what Trevor was referring to). As for attaching to exports or window, that's going to have to be something that you do by hand regardless. If everything is added to the exports, then there's no point in wrapping in the first place...
- endtime 16y agoWell, what I'd like to do is have e.g. mymodule.coffee: x: 5 y: (z) -> z * z main.coffee: load("mymodule") puts mymodule.y(5) I could set this up manually, of course, but if I wanted to do things manually I wouldn't be using CoffeeScript. :p
- TrevorBurnham 16y agoYes, I meant that the JavaScript "module pattern" is implemented by default, and the language prevents you from declaring globals by mistake. So, you get most of the benefits of the proposed JS module syntax.