本文介绍了来自Coffeescript的Bloated JS想要返回一切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有这个Coffeescript:

I've got this Coffeescript here:

brew = (args...) =>
  for e in args
    alert e
    null

brew('fo', 're', 'eo');

我希望我不需要把null放到那里,编译为:

I wish I didn't need to put null there to get it to work, but alas, that compiles to this:

brew = function() {
  var args, e, _i, _len, _results;
  args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
  _results = [];
  for (_i = 0, _len = args.length; _i < _len; _i++) {
    e = args[_i];
    alert(e);
    _results.push(null);
  }
  return _results;
};

brew('fo', 're', 'eo');

但现在我有3个不必要的行:

But now I have 3 unnecessary lines:

 _results = [];
 _results.push(null);
 return _results;

任何提示?

推荐答案

这是什么

brew = (args...) -> args.forEach alert

可编译为

var brew,
    __slice = [].slice;

brew = function() {
  var args;
  args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
  return args.forEach(alert);
};

brew('fo', 're', 'eo');

这篇关于来自Coffeescript的Bloated JS想要返回一切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 10:41