الخميس، 26 ديسمبر 2013

CoffeeScript: how to do f(a(1), b(2), c(3)) braceless style?

This is what your code translates to:

var f5, f6, f7;f5 = function(x) { return 500 + x;};f6 = function(x) { return 600 + x;};f7 = function(x) { return 700 + x;};console.log(f5(5, f6(6, f7(7)))); //505console.log(f5(5, f6(6, f7(7)))); //505console.log(f5(5, f6(6, f7(7)))); //505console.log(f5(5), f6(6), f7(7)); //505, 606, 707

So in your 1st 3 logs you are calling f5 which only takes in one parameter therefore the rest of the arguments are ignored.

What you can do is this:

console.log( f5 5 f6 6 f7 7 )

The multiple lines forces it to run as individual functions

You can do the same for objects, putting newlines adds a comma:

obj = a: 42 b: 23

View the original article here

ليست هناك تعليقات:

إرسال تعليق