JavaScript 原来 babel 自带尾递归优化

mizuhashi · May 09, 2016 · Last by 1272729223 replied at May 09, 2016 · 2495 hits

可能火星

输入:

function a(b){
  if(b<0)return "hehe"
  return a(b-1)
}

输出:

"use strict";

function a(_x) {
  var _again = true;

  _function: while (_again) {
    var b = _x;
    _again = false;

    if (b < 0) return "hehe";
    _x = b - 1;
    _again = true;
    continue _function;
  }
}

这个没见过的语法看了半天才发现是 goto...不过只能用来标记循环

能注释一下输出的代码吗?看不懂。

You need to Sign in before reply, if you don't have an account, please Sign up first.