简体   繁体   English

ES6类中的递归方法是否利用了TCO(尾调用优化)?

[英]Do recursive methods in ES6 classes take advantage of TCO (Tail Call Optimization)?

So I have read that ECMAScript6 (ES6) is capable of TCO. 所以我读过ECMAScript6(ES6)能够进行TCO。 I have seen this demonstrated as: (crude example with no practical purpose...) 我已经看到这表现为:( 粗略的例子,没有实际意义......)

const tcoFn = (acc) => {
  if (acc > 10) {
    return acc
  } else {
    return tcoFn(acc + 1)
  }
}

My question is whether or not it is known that we get TCO in an ES6 class? 我的问题是,我们是否知道我们在ES6课程中获得TCO? So, 所以,

class TCOish {
  tcoMethod(acc) {
    if (acc > 10) {
      return acc
    } else {
      return tcoMethod(acc + 1)
    }
  }
} // End class definition

After some searching on the Interwebs this remains unclear to me and I am wondering if there is a definitive answer that someone can point me to? 在对Interwebs进行一些搜索之后,这对我来说仍然不清楚,我想知道是否有人可以指出我的确定答案?

Also worth noting is that this will be used in Node app where we do not care about the browser or transpiling. 另外值得注意的是,这将在Node应用程序中使用,我们不关心浏览器或转换。

Thank you. 谢谢。

So,from the link that Andy provided in the comments above, it looks like the answer is not yet. 所以,从Andy在上面的评论中提供的链接来看,答案还没有。 This seems to be generally true excepting WebKit which is a bit ahead in the TCO arena. 除了在TCO领域领先一步的WebKit之外,这似乎是正确的。 Worth noting is that the value of this "answer" will degrade over time as TCO support grows. 值得注意的是,随着TCO支持的增长,这种“答案”的价值会随着时间的推移而降低。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM