3 ms·
Why would it be "totally wild" coming from a JS background when the corresponding JS code: for(var i=0; i<10; ++i) { powers_of_x.push((x) => i^x);
by masklinn 7y ago
Why would it be "totally wild" coming from a JS background when the corresponding JS code:
for(var i=0; i<10; ++i) {
powers_of_x.push((x) => i^x);
}
behaves the exact same way for the same reason?
By definition, a closures closes over its definition context, it doesn't capture the values at definition time but instead keeps referring to said definition context. If the definition context is mutable and modified, the closure reflects that change when it's finally invoked.
- deleted 7y ago[deleted]