开发者社区> 问答> 正文

coffee-script 编译后,怎么才能避免出现不需要出现的return呢

coffeescript 新手,请多多指教。

coffee上的代码是:

refine = (wheat,chaff...) -> 
    console.log "The best: #{wheat}"
    console.log "The rest: #{chaff.join(',')}"

refine 'one','two','three','four'

编译出来后:

(function() {
  var refine,
    __slice = [].slice;

  refine = function() {
    var chaff, wheat;
    wheat = arguments[0], chaff = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
    console.log("The best: " + wheat);
    return console.log("The rest: " + (chaff.join(',')));
  };

  refine('one', 'two', 'three', 'four');

}).call(this);

refine函数里面最后一行,多了return,实际中应该不需要这个return的,为什么会被这样编译出来呢?
需要去掉吗?怎么去掉?
不需要去掉吗?为什么?

展开
收起
杨冬芳 2016-06-16 17:31:47 1971 0
1 条回答
写回答
取消 提交回答
  • IT从业

    最后一行写一个return或者undefined

    refine = (wheat,chaff...) -> 
        console.log "The best: #{wheat}"
        console.log "The rest: #{chaff.join(',')}"
        return
    
    refine 'one','two','three','four'
    

    or

    refine = (wheat,chaff...) -> 
        console.log "The best: #{wheat}"
        console.log "The rest: #{chaff.join(',')}"
        undefined
    
    refine 'one','two','three','four'
    

    http://stackoverflow.com/questions/7391493/is-there-any-way-to-not-ret...

    2019-07-17 19:41:34
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载