News for hackers. Stuff that matters.
Re:WTFPython – Understanding Python through surprising snippets by masklinn on Monday December 23, 2019 @04:39AM (#21862509)
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.

There are no comments on this comment yet.