Today i looked at JavaScript closures. There i came across a thing closure comes in when an inner function defined inside an outer function. So when outer function exits and returns the inner function reference then a hidden reference returns along with the reference of inner function.
Now my question is when that hidden reference created? And the hidden reference have the references of all local variables of outer function. Now my second question..
If any variables local to a loop scope are also being referenced by hidden pointer. But those variables get destroyed after loop scope ends up, how it gets handled?
Now have a look at code snippet....
[code=javascript]
function outer(){
var var1 = some_value;
var inner = function(){some _code;}
return inner;
}
[/code]
Here when inner returns then a closure of outer's local variables get created.
so the reference of inner variable being referenced by hidden pointer or only variable var1?
I think experts can get my point of view.
Please answer these questions!
Now my question is when that hidden reference created? And the hidden reference have the references of all local variables of outer function. Now my second question..
If any variables local to a loop scope are also being referenced by hidden pointer. But those variables get destroyed after loop scope ends up, how it gets handled?
Now have a look at code snippet....
[code=javascript]
function outer(){
var var1 = some_value;
var inner = function(){some _code;}
return inner;
}
[/code]
Here when inner returns then a closure of outer's local variables get created.
so the reference of inner variable being referenced by hidden pointer or only variable var1?
I think experts can get my point of view.
Please answer these questions!
Comment