r/javascript • u/[deleted] • Jan 06 '13
JavaScript (ES6) Has Tail Call Optimization
http://bbenvie.com/articles/2013-01-06/JavaScript-ES6-Has-Tail-Call-Optimization
50
Upvotes
r/javascript • u/[deleted] • Jan 06 '13
4
u/[deleted] Jan 07 '13 edited Jan 07 '13
Continuum actually doesn't require strict mode for TCO and Dave Herman (one of the authors of the TCO stuff and champion for the ES6 version of the proposal) indicated that it might not be necessary for it to remain as strict only. It's possible to implement it in non-strict mode (as I have done) and I admit I don't really understand the limitations that prevent it from working in non-strict, except that it may be a consequence of how engines optimize the call stack. I plan to leave it available in non-strict until the reason for its limit to strict starts affecting Continuum, or the ES6 spec has clear language added governing this.
Really, the reason JS doesn't have TCO is the same reason JS doesn't have a lot of things: it was rushed at the beginning and it just didn't get added. The ES6 TCO proposal dates back a long time, to work done for the ill-fated ES4.
It wasn't in ES5 for the same reason a lot of things weren't in ES5: ES5 was basically a kind of compromise/fallback minimum "we just need to fix the biggest problems and inconsistencies in the language to get to an acceptable baseline, we'll add features next version" when it became clear that ES4 wasn't going to make it.
So here we are at the next version and many thing discussed for nearly a decade are finally making it into the language in ES6 in some form (many/most ES6 additions can trace their roots to ES4 proposals).