【发布时间】:2015-08-05 05:06:10
【问题描述】:
今天,我正在阅读harmony:proper_tail_calls 提案,我注意到在references 中有一个链接,上面写着“Brendan discovers that ES5/strict enables TCO.”
ES5/strict “启用” TCO 是什么意思?起初我认为正确尾调用的初始实现可以在 ES5/strict 模式下使用。但是,这些基准测试显然并非如此:
- ES5/strict TCO (n = 10000)。
- ES5/strict TCO (n = 1000)。
我在上述基准测试中使用了以下两个函数:
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);
}
无论如何,我的问题是:如何在 ES5/严格模式下“启用”正确的尾调用?
【问题讨论】:
标签: javascript ecmascript-5 strict ecmascript-harmony tail-call-optimization