Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function outer()
- {
- var arr = [];
- var i;
- for (i = 0; i < 4; i++)
- {
- // storing anonymus function
- arr[i] = function () { return i; }
- }
- // returning the array.
- return arr;
- }
- var get_arr = outer();
- console.log(get_arr[0]());
- console.log(get_arr[1]());
- console.log(get_arr[2]());
- console.log(get_arr[3]());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement