jasonpgignac
jasonpgignac

Reputation: 2306

How to call a function on a newly defined function in CoffeeScript

Am getting used to CoffeeScript, and have what is probably a stupid question: how do I call a function on an anoymous function? So here's the javascript example

baz = function() {
   this.do_something_to_this_function
}
foo = {
    bar: function() {
        // do something to some data
    }.baz()
}

How would I do this same thing in CoffeeScript?

I know I could do this:

barfunc = => blah blah blah
foo = {
    bar: barfunc.baz()
}

It seems there must be a prettier way?

Upvotes: 0

Views: 78

Answers (1)

Jeremy Roman
Jeremy Roman

Reputation: 16345

Just add parentheses.

foo =
  bar: (=> blah blah blah).baz()

Upvotes: 2

Related Questions