I know that this form:
var foo = function bar() {};
will leak the bar
name to the enclosing scope and create two functions in jscript
.
How about:
var foo = function foo() {};
?
It still leaks the name to enclosing scope, but it's in there anyway (thx to var foo
).
I know it will be defined in the whole scope, but will it create two functions and immediately dereference/destroy one of them or is this still causing a leak?
In this situation:
var bar = function() {
foo();
var foo = function foo() {};
}
Will we have two function objects inside bar()
?
edit
Ok it most definitely creates two function objects, now the question is: does the function created by named definition get dereferenced and cleaned up by GC after the var foo
line, so there is no more than one 'live' foo
instance at any moment in the code above?
Or will IE being IE leave it dangling forever, since there's no way to "dereference" the foo
created by the definition and it shouldn't even be there in the first place?