3 ms·
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.
by tkahn6 15y 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-in-python http://stackoverflow.com/questions/233673/lexical-closures-i...