Consider the following CoffeeScript class:
class Event
trigger : (args...) =>
...
bind : (args...) =>
...
The use case would be:
message_received = new Event()
message_received.bind(alert)
message_received.trigger('Hello world!') # calls alert('Hello world')
Is there a way to write the Event class in such manner that the .trigger(...) call would have the “callable object” shortcut:
message_received('Hello world') # ?
Thank you!
You need to return a function from the constructor, which is extended with the properties from the current instance (which in turn is inherit from
Event.prototype).Compiled result