Is it possible in iced coffee script
to make async constructor:
class Animal
constructor: (autocb) ->
#some async action here
And call it like:
await new Animal, defer(animal)
When I try to do it, got error:
unexpected ,
Is it possible in iced coffee script
to make async constructor:
class Animal
constructor: (autocb) ->
#some async action here
And call it like:
await new Animal, defer(animal)
When I try to do it, got error:
unexpected ,
In CoffeeScript commas are used as separators for arguments. For example:
Optionally you may put parentheses around arguments to make it more explicit:
However you may not put a comma between the function and the arguments:
The same goes for constructor functions:
However you can't put a comma between
new Animal
and the first argument:The same goes for
await
:However you can't put a comma between the function and the first argument:
So to answer your question: yes, it is possible to make an async constructor in iced coffee script. Like all asynchronous functions the last argument must always be the callback function generated by
defer
.Next time when the compiler says
unexpected ,
just remove the comma. It's as simple as that.