-
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
Add support for dashes in variable names, mangle them #2345
Comments
We've talked about doing this before -- see previous tickets. The reason why we don't is because it breaks interoperability with JavaScript, and with naming properties on your object at runtime. If CoffeeScript was an entirely new engine, we would absolutely use dashes -- but it isn't, so we have to use JS identifiers. |
Not sure how exactly it breaks interop with js. JS module: exports.forEach = function() {return 1};
exports['for-each'] = function() {return 2}
exports.reduceLeft = function() {return 3}; Coffee module analog: exports.for-each = -> 1
exports['for-each'] = -> 2
exports.reduce-left = -> 3 So, because Example: user = document.query-selector('.user')
user.add-event-listener 'click', ((event) -> console.log event), yes
id = window.set-interval ->
console.log 'hello'
, 1000
window.set-timeout (-> window.clear-timeout id), 1500
encoded = encode-URI-component string
number = parse-int '5'
string = number.to-string!
page-text = document.query-selector('body').inner-text
logged-in = $('body').has-class 'logged-in'
obj = {a: 1, b: 2}
descriptors = Object.get-own-property-names(obj)
.map((name) -> Object.get-property-descriptor obj, name) |
All that I mean by "interoperability" is that functions and variables are named the same thing in JS as they are in CoffeeScript. If you always have to do the mental translation between the two names, interoperability suffers. Especially when properties can be named dynamically.
Should name be written as |
Alternatively:
Should |
@satyr the first one. Just one simple rule: identifiers (whatever these are called) always mangled.
|
Sounds like workable. After all:
|
-1 |
Why dashes?
Cons:
-
will be prohibited from using as OP without indenation likea - b
(which is good IMO).Examples
Examples
Clojure. Pretty readable.
The text was updated successfully, but these errors were encountered: