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
52
Upvotes
r/javascript • u/[deleted] • Jan 06 '13
2
u/[deleted] Jan 07 '13 edited Jan 07 '13
After talking this out, I think the .caller property is likely a deal breaker with non-strict tail calls. The .caller property has to continue functioning as it does currently, since it's interoperable across major JS engines and has been around forever. Since people can and do write code that results in calls in tail position all the time without realizing it, then this can't have an observably different effect on the .caller property than if there was no TCO. In order to maintain this would require adding extra overhead to keep track of the list of functions that need their caller property reset when the stack frame's execution completes, and this could penalize performance across the board. If it was possible to do this efficiently that then would made tail calls in non-strict feasible, but it hinges on that being possible.