By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

How JQuery knows that variable is from the loop?

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

Expand|Select|Wrap|Line Numbers
  1. for (var i = 0; i < 100; ++i) {
  2.     myElements[i].onclick = ( function(n) {
  3.         return function() {
  4.             alert( 'You clicked on: ' + n );
  5.         };
  6.     })(i);
  7. }
How function (self invoking anonymous function) knows that n=1?
Jun 17 '15 #1

✓ answered by Dormilich

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

Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
How function (self invoking anonymous function) knows that n=1?
because 1 was passed to it.
Jun 17 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.