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

It's a common enough optimization for JS engines in some form.

In particular, if the closure only reads the variable and nothing can write it, it's way cheaper in terms of performance to just create a separate lexical environment for the closure that contains the things it reads so that you don't have to keep walking up the scope chain on bareword lookups in the closure.

The fact that things then end up not referenced and can be gced is just a side-effect of the primary goal of the optimization: faster access to variables in a closure.



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

Search: