Leon
Leon

Reputation: 2886

how should I chain function call in coffeescript

This coffeecode

obj
  .func1()
  .func2()

will result in

obj.func1().func2();

this work find.

But when I type this

obj
  .func1 "aaa"
  .func2 "bbb"

it will result in

obj.func1("aaa".func2("bbb"));

I must type like this

obj
  .func1('aaa')
  .func2('bbb')

that result in javsscript

obj.func1('aaa').func2('bbb');

Is there a way to omit parentthese when chain function in coffeescript?

Upvotes: 16

Views: 8436

Answers (2)

boh
boh

Reputation: 1547

This issue has just been fixed here.

So, for e.g.:

obj
 .func1 "aaa"
 .func2 "bbb"

will be compiled to

obj.func1("aaa").func2("bbb");

You may need to use the latest version at master branch for now, in npm:

npm install -g http://github.com/jashkenas/coffee-script/tarball/master

Upvotes: 19

matyr
matyr

Reputation: 5774

No way for now. There are ongoing discussions for enabling it:

Upvotes: 9

Related Questions