Advertisement
boris-ivanov

Untitled

Jul 25th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. function outer()
  2. {
  3. var arr = [];
  4. var i;
  5. for (i = 0; i < 4; i++)
  6. {
  7. // storing anonymus function
  8. arr[i] = function () { return i; }
  9. }
  10.  
  11. // returning the array.
  12. return arr;
  13. }
  14.  
  15. var get_arr = outer();
  16.  
  17. console.log(get_arr[0]());
  18. console.log(get_arr[1]());
  19. console.log(get_arr[2]());
  20. console.log(get_arr[3]());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement