result = range 1, 3
.concat range 4, 6
.map (x) -> x * x
.filter (x) -> x % 2 is 0
For example, the leading `.map` closes the open call to `range` and the open call to `concat`. Before 1.7.0, `.map` would be called on the number 6.
Re:CoffeeScript 1.7.0
by bobbyi_settv on Tuesday January 28, 2014 @04:40PM
(#7139954)
It would have been nice if their code example for this feature showed how the code would have looked in the prior version of Coffeescript.
$('body')
.click (e) ->
$('.box')
.fadeIn('fast')
.addClass '.active'
.css 'background', 'white'
If I omit as many parentheses as possible. Also for the other example: result = range(1, 3)
.concat(range 4, 6)
.map((x) -> x * x)
.filter (x) -> x % 2 is 0It would look like
result = range(1, 3).concat(range 4, 6).map((x) -> x * x).filter (x) -> x % 2 is 0
or result = range 1, 3
result = result.concat range 4, 6
result = result.map (x) -> x * x
result = result.filter (x) -> x % 2 is 0Instead of this:
$ 'body'
.click (e) ->
$ '.box'
.fadeIn 'fast'
.addClass '.active'
.css 'marginRight', '10px'
You used to have to do this: $('body') .click (e) -> $('.box') .fadeIn('fast') .addClass('.active') .css 'marginRight', '10px'
Note the extra ( )s, if not used, the next method call is not recognized as a method call but rather part of the previous call's argument. The last method call did not and does not need to be closed with ( ).
This is hugely important for libraries like d3 with super long call chains.
I feel like this is an important improvement, but I don't really understand what it means. Can someone elaborate on what this means and how it works? How did things used to be different?