-
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
Facilitate jQuery-like chaining #944
Comments
Yes. |
Personally, I prefer indentation when chaining. I would probably write that code as:
|
Indentation doesn't matter in this case actually. A line leading with a dot is considered continued and thus doesn't terminate an expression or create a block. What's missing here is a rule to make such dots close implicit calls. |
This has come up a few times before, but without a satisfactory consensus. There's likely to be an overhaul of how indentation and function arguments are handled at some point, though not for 1.0. Someone needs to make a concrete proposal on how every possible case should be handled. For instance, if we wanted to support jQuery-style chaining without parentheses, we'd need to support things like
where the indentation of the last line means that |
This has come up before, and I'm still of the opinion that it's an abuse of indentation. Leading dot accessors should attach to the final value of the previous line, and not cause the previous line to be implicitly wrapped in parentheses. |
Since jQuery-like chaining is very popular in javascript would it make sense to support (and improve) it in coffeescript?
javascript:
$('#foo')
.attr('a', 'boo')
.append(c, d, e)
.show()
The equivalent cs is identical.
However, It would be great if we could instead write (note there is no indentation):
$ '#foo'
.attr 'a', 'boo'
.append c, d, e
.show()
i.e., if a line starts with a dot and is not indented coffeescript understands that chaining is implied with the result of the entire previous line. (An indented line would still result in the current behavior)
The text was updated successfully, but these errors were encountered: