This repository has been archived by the owner on Feb 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
CS2 Discussion: Features: Introduce keyword “using” for controlled scoping #57
Labels
Comments
I'm afraid this might be impractical due to JS not distinguishing between functions/methods and variables: It's all variables. JS programmers commonly use variables in external scopes to require and alias functions from other modules, like this:
If we want to use
|
What about the reverse? Imagine a keyword
Oops, I guess I just re-invented |
Closing due to lack of interest, and the consensus from other threads that we aren’t revisiting scoping at this time. |
coffeescriptbot
changed the title
Introduce keyword "using" for controlled scoping
CS2 Discussion: Features: Introduce keyword “using” for controlled scoping
Feb 19, 2018
Migrated to jashkenas/coffeescript#4949 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
MoonScript has a
using
keyword, which allows you to create a new scope only pulling in the variables from the parent scope that you need, along with being able to pass in nil to create an entirely new scope.local
in Lua works the same way aslet
does in JavaScript, so there's no Lua-specific magic going on here.using
is a compile-time feature which checks for the variables used outside of theusing
block against the ones provided, or lack thereof, and declares them locally accordingly.Here's how it'd work in JavaScript, assuming we don't limit the keyword to just function definitions.
Compiles to:
However, because there might be some random
using
function out there in the wild, a viable alternative is limiting the feature to functions, like MoonScript does.The text was updated successfully, but these errors were encountered: