Hacker News new | ask | show | jobs
by tkahn6 5399 days ago
This is a property of how javascript and python do closures. In the above code i refers to the same piece of memory in every case. So f and g are closed over i. The reference is preserved but the value is not.

This behavior is the motivation behind the do keyword in CoffeeScript.

Here's more on this:

http://stackoverflow.com/questions/233673/lexical-closures-i...