How JQuery knows that variable is from the loop?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gintare
    New Member
    • Mar 2007
    • 103

    How JQuery knows that variable is from the loop?

    Bellow is the example from:
    http://james.padolsey. com/javascript/closures-in-javascript/

    Code:
    for (var i = 0; i < 100; ++i) {
        myElements[i].onclick = ( function(n) {
            return function() {
                alert( 'You clicked on: ' + n );
            };
        })(i);
    }
    How function (self invoking anonymous function) knows that n=1?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    How function (self invoking anonymous function) knows that n=1?
    because 1 was passed to it.

    Comment

    Working...