function Foo() {
var num = 1;
function Bar() {
num++;
console.log(num);
}
function Dummy() {
Bar();
}
this.func = Dummy
}
let fooInstance = new Foo();
fooInstance.func(); // print 2
what I don't understand is:
after new Foo()
is called, function Foo()
get popped on the stack, any local variables created during new Foo()
is called should be destroyed, then how come fooInstance.func()
can still read something which has been already destroyed?
or does function Foo()
not popped on the stack after new Foo()
is called?