Is there any way to not return something using CoffeeScript?

前端 未结 5 1065
刺人心
刺人心 2020-11-27 13:03

It seems like CoffeeScript automatically returns the last item in a scope. Can I avoid this functionality?

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 13:06

    Yes , with a return as the last line of a function.

    For example,

    answer = () ->
      42
    
    extrovert = (question) -> 
      answer()
    
    introvert = (question) ->
      x = answer()
      # contemplate about the answer x
      return 
    

    If you'd like to see what js the coffee compiles to, try http://bit.ly/1enKdRl. (I've used coffeescript redux for my example)

提交回复
热议问题