This is going to change with the new Ecmascript 6 specifications, where a so called tail-call optimzation has been added to the interpreter. This allows the interpreter to excecute an iterative process in constant space even if that iterative process is described by a recursive function. The tail-recursive implementation in ES6 allow to use the ordinary function invocation to express iterative processes so that special iteration constructs are useful only as syntactic sugar.
If you are familiar with functional libraries like lodash or underscore, you know how we can implement functions like each and reduce by relying on looping constructs. Following are two examples of a recursive implementation of each and reduce that take advantage of the upcoming ES6 tail-call optimization in order to express a liner iteration process.
Tail-recursive each (linear iterative process in ES6)
Tail-recursive reduce (linear iterative process in ES6)
Boom! With ES6 we can have linear iterative process in constant space by calling a recursive function, thanks the tail-recursive implementation of the interpreter. Read more about tail-call optimization:
- ES6 tail call optimization
- EcmaScript Tail-position calls specs
- ES6 Tail-call optimization implementation status