View Single Post
  #2 (permalink)  
Old July 22nd, 2010, 06:32 PM
nzakas's Avatar
nzakas nzakas is offline
Wrox Author
 
Join Date: Dec 2004
Location: Peabody, MA, USA.
Posts: 217
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Hi Mike,

You're testing the result incorrectly. The way you should be testing it is:
Code:
var functions = createFunctions();

alert(functions[0]());   //10
alert(functions[1]());   //10

//etc.
What you're doing is just alerting the array of functions, which will appear to be the same in both cases.

To answer your other questions: i is passed to num via (i). The anonymous function is being immediately called by placing parentheses at the end. i is the value being passed into the function and num is the name of the argument for that function.
__________________
Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/