-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Feature request] Import keyword #327
Comments
It's been discussed before. General consensus is that it's a great feature for code compacting and DSL's etc. However, there was some disagreement about whether * would work nicely. Essentially it would require the use of eval and it was dropped because performance concerns. Personally I think that these concerns are in the most part unfounded, since in real practical use, the eval would be called very few times and so would have a minimal impact to the running time. |
I found the issue where this was discussed. At this point I don't understand why we need to use eval when using "*" in the import statement. this: import Obj.* could translate to: for prop of Obj prop: Obj[prop] no? |
you can't do |
Dope.... :) |
As a proof-of-concept, I have a macros branch which defines an
This did not make it to the core. It is also several commits behind master so it doesn't have the new fixes applied lately. I no longer support it, but feel free to adopt it for your own needs.
You can also use destructuring assignments to introduce local variables:
And last you could also mix in properties into the current scope (whether this is bad or not I won't discuss):
Jeremy: how about doing something similar to the macro version in core? The question seems to pop all too often and it should be an easy one to address. |
TomasM: Quick note -- you don't need to wrap your CoffeeScript in a closure wrapper, one is already provided for you. This feature has been discussed before, but there are a couple of reasons why we're not able to add it. The fundamental issue is that you can't dynamically set local variables in JavaScript without resorting to MyFrameworkNamespace.Mixin.Observable: {}
As mentioned before, pattern matching can be used to extract multiple properties from an object as local variables at a stroke:
Really, as long as you have to name the properties, I think that local variables are the way to go. Closing as a |
Thank you everybody for your replies. For me, pattern matching seems too verbose. So I will be using weepy's extension (probably will extend it to allow aliasing). It is awsome how easy it is to extend coffeescript! |
Hi,
I'm working on an experimental framework with coffeescript. All my classes/mixins are namespaced like this:
...and so on. In my code I do:
Now idealy i would like a smart Import keyword that would do the imports for me:
The implementation for this would be very simple. What do you think about this?
EDIT:
Perhaps this would be allowed as well:
The text was updated successfully, but these errors were encountered: