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.”
What does it mean that ES5/strict “enables” TCO? At first I thought that initial implementations of proper tail calls were available in ES5/strict mode. However, that is clearly not the case as demonstrated by these benchmarks:
- ES5/strict TCO (n = 10000).
- ES5/strict TCO (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?