4 ms·
> Leading . now closes all open calls, allowing for simpler chaining syntax. I feel like this is an important improvement, but I don't really understand what i
by tieTYT 13y ago
> Leading . now closes all open calls, allowing for simpler chaining syntax.
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?
- xixixao 13y agoresult = 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.
- bobbyi_settv 13y agoIt would have been nice if their code example for this feature showed how the code would have looked in the prior version of Coffeescript.
- ndnichols 13y agoIt 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 0
- xixixao 13y ago$('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 0
- rayshan 13y agoInstead 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.