Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think that link needs a bit of updating - JS has lexical scoping and tail call elimination now.


> JS has [...] tail call elimination now.

In a very narrow hay of "has", as in "ES2015 the spec has it, but no JS runtime implements it yet": http://kangax.github.io/compat-table/es6/#proper_tail_calls_...

I'm not trying to be a contrarian. It's just that i see lots of JS developers excited about superfluous things like class syntax or symbols, whereas real game changing additions like proper tail calls seem to pass by unnoticed, and unimplemented by JS runtimes :(


I tried to create an infinite loop in Firefox and got a "InternalError: too much recursion". Then when I tried it in Chrome I got "Uncaught RangeError: Maximum call stack size exceeded".

function x() { return x(); }


I think you misunderstood "now". It's "now" as in ES6/ES2015, not ES5 which the browsers are running by default.


That's still expected?


It's a recursive tail call. It should run forever, like the following Scheme code.

(define (foo) (foo))

(foo)


Ah, right, yes I get what you mean.

The main problem is still that Chrome and Firefox don't support tail call elimination. Babel (6to5) and Traceur do.


They don't. They support an optimization for self recursive calls but not general tail call elimination.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: