简体   繁体   English

在ES5 /严格模式下如何启用正确的尾声?

[英]How are proper tail calls enabled in ES5/strict mode?

Today, I was reading the harmony:proper_tail_calls proposal and I noticed that in the references there was a link which read, “ Brendan discovers that ES5/strict enables TCO. 今天,我正在阅读“ harmony:proper_tail_calls”提案,我注意到在参考文献中有一个链接,内容为:“ Brendan发现ES5 / strict启用了TCO。

What does it mean that ES5/strict “enables” TCO? ES5 / strict“启用” TCO是什么意思? At first I thought that initial implementations of proper tail calls were available in ES5/strict mode. 起初,我认为可以在ES5 /严格模式下使用适当的尾部调用进行初始实现。 However, that is clearly not the case as demonstrated by these benchmarks: 但是,显然不是这些基准所显示的情况:

  1. ES5/strict TCO (n = 10000). ES5 /严格的总体拥有成本 (n = 10000)。
  2. ES5/strict TCO (n = 1000). ES5 /严格的总体拥有成本 (n = 1000)。

I used the following two functions in the above benchmarks: 在上述基准测试中,我使用了以下两个功能:

function without_tco(x) {
    if (x === 0) return x;
    return without_tco(x - 1);
}

function with_tco(x) {
    "use strict";
    if (x === 0) return x;
    return with_tco(x - 1);
}

Anyway, my question is: how are proper tail calls “enabled” in ES5/strict mode? 无论如何,我的问题是:在ES5 /严格模式下如何正确启用尾部调用?

It means that strict mode makes calls in proper tail position guaranteed to be able to be implemented as tail calls, since it prohibits anything that might interfere with that optimization; 这意味着严格模式可以确保处于正确尾部位置的调用能够保证被实现为尾部调用,因为它禁止任何可能干扰该优化的内容。 namely that a strict-mode function cannot be accessed through a caller property. 即严格模式功能不能通过caller属性访问。 It doesn't mean “enables” in the sense that Firefox implemented it already. 从Firefox已实现的意义上讲,这并不意味着“启用”。

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

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