Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function simplefunc(value) {
- var local_variable = value;
- function innerfunc() {
- console.log(local_variable);
- }
- return innerfunc;
- }
- var fa = simplefunc(1);
- var fb = simplefunc(2);
- fa(); // prints 1
- fb(); // prints 2
- var fc = simplefunc(3);
- fc(); // prints 3
- fa(); // still prints 1
- fb(); // still prints 2
- // simplefunc()가 불릴때마다 매번 새로운 scope가 생성되고
- // 각각은 서로와 무관하므로 각각이 바라보는 local_variable은
- // 대상이 다르다.
Add Comment
Please, Sign In to add comment