3 ms·
Also worth mentioning is the closure gotcha: when you create functions in a loop, the functions' context points to the context of the latest iteration of the lo
by rhizome31 13y ago
Also worth mentioning is the closure gotcha: when you create functions in a loop, the functions' context points to the context of the latest iteration of the loop. Other languages might have this issue as well and provide alternatives based on map-style constructs. In Python, you can take advantage of the behaviour described by the OP to make your inner functions have their own context, which is initialized when the function gets created.
- wahnfrieden 13y agoIn other words, function definitions create scope.