If I have a self-destroying function
function tempFunc() {
//do some stuff, then...
tempFunc = function() {return;}
}
or
function tempFunc() {
//do some stuff, then...
delete tempFunc;
}
What happens to the origin开发者_运维百科al code of tempFunc? Is it held in memory anywhere? How is the situation changed if the function leaves behind something a bit more permanent e.g. creates an object which has access to variables contained within the function's closure.
When there are no more referenced to the function, it can be garbage-collected.
If there are referenced through closures, it can't.
精彩评论