how should I chain function call in coffeescript

2019-03-24 16:04发布

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?

2条回答
唯我独甜
2楼-- · 2019-03-24 16:20

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
查看更多
登录 后发表回答