Skip to content

Namespaces/modules sugar #684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danielribeiro opened this issue Sep 14, 2010 · 3 comments
Closed

Namespaces/modules sugar #684

danielribeiro opened this issue Sep 14, 2010 · 3 comments

Comments

@danielribeiro
Copy link

There are some ways to create namespaces than span several files in javascript (such as described here and argued against in here). It would be nice if coffescript featured a namespace or module (from those coming from ruby) way to make namespaces span several files (closures can't really do it).

The compiled code can join them all in one closure, but for writing it would be much nicer. Also kinda like python's "from x import a, b, c".

@jashkenas
Copy link
Owner

Modules in JavaScript are usually just JS objects -- which is all well and good, in my opinion. I don't think we need special language support for this... especially because we have destructuring assignment, which can be used to import a number of properties from a module in a single blow.

For previous tickets, see: #218, #292, #327, #452, and #636.

@danielribeiro
Copy link
Author

Very nice questions and answers. However, doing it all the time can be quite a big performance hit. If a module is divided in 30 files, and all of them import 10 classes, you will have 300 assingnments instead of 0. This gets even bigger for several modules. And it has a terrible sideback of poluting the default this scope when importing everything at top level (which is the only way to do this without eval'ing the destructuring assignment inside a function scope).

It is also interesting that this can be implemented with the inline pre-processor: http://github.com/chrislloyd/roast

@danielribeiro
Copy link
Author

There are also other proposals for ecmascript: http://wiki.ecmascript.org/doku.php?id=strawman:simple_modules. RingoJS also comments a lot of these.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants