How do I create a named function expressions in CoffeeScript?

人盡茶涼 提交于 2019-12-13 17:23:41

问题


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

var a = function b (param1) {}

or

return function link (scope) {}

回答1:


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

a = (param1) ->
    console.log param1



回答2:


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'


来源:https://stackoverflow.com/questions/22221270/how-do-i-create-a-named-function-expressions-in-coffeescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!