javascript - coffee-script 编译后,怎么才能避免出现不需要出现的return呢?
天蓬老师
天蓬老师 2017-04-10 15:18:48
[JavaScript讨论组]

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的,为什么会被这样编译出来呢?
需要去掉吗?怎么去掉?
不需要去掉吗?为什么?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(1)
迷茫

最后一行写一个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...

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号