screenm0nkey
screenm0nkey

Reputation: 18795

How do I create a named function expressions in CoffeeScript?

How do I create a named function expressions in CoffeeScript like the examples below?

var a = function b (param1) {}

or

return function link (scope) {}

Upvotes: 1

Views: 1226

Answers (2)

xsh.7
xsh.7

Reputation: 6250

I may be a bit late to the party, but I just realised that you actually create named functions when using the class keyword.

Example:

class myFunction
  # The functions actual code is wrapped in the constructor method
  constructor: ->
    console.log 'something'

console.log myFunction # -> function AppComponent() { ... }
myFunction() # -> 'something'

Upvotes: 5

spikeheap
spikeheap

Reputation: 3887

Coffeescript doesn't support the latter (named functions), but the former can be achieved with

a = (param1) ->
    console.log param1

Upvotes: 0

Related Questions