Guest User

Untitled

a guest
Nov 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. function simplefunc(value) {
  2. var local_variable = value;
  3.  
  4. function innerfunc() {
  5. console.log(local_variable);
  6. }
  7. return innerfunc;
  8. }
  9.  
  10. var fa = simplefunc(1);
  11. var fb = simplefunc(2);
  12.  
  13. fa(); // prints 1
  14. fb(); // prints 2
  15.  
  16. var fc = simplefunc(3);
  17. fc(); // prints 3
  18.  
  19. fa(); // still prints 1
  20. fb(); // still prints 2
  21.  
  22. // simplefunc()가 불릴때마다 매번 새로운 scope가 생성되고
  23. // 각각은 서로와 무관하므로 각각이 바라보는 local_variable은
  24. // 대상이 다르다.
Add Comment
Please, Sign In to add comment