Hacker News new | ask | show | jobs
by teraflop 3568 days ago
Python's behavior is the same as Go's. For example, this code:

    l = []
    for i in xrange(3):
      l.append(lambda: i)
    print [f() for f in l]
prints [2, 2, 2].
1 comments

Same in javascript:

    var fns=[];
    for (var i=0; i<3; i++) {
       fns.push(function(){return i});
    };
    fns.map(function(x) { return x.call(); });
Returns

    [ 3, 3, 3 ]