If I assign an anonymous function to an element's event in a function then the event will have access to the "environment" of the function, even after the function is done.
What happens if I change the element's event function? Does that previous "environment" get garbage collected or is it still in memory?
Or what happens if I remove the element from the DOM?
function blah(div)
{
var a = 1;
div.onclick = function(){ alert(a); }; // this alerts 1 as expected because a is in the "environment" of the onclick function
}
blah(someElement);
// somewhere else
someElement.onclick = function()
{
// i know a is inaccessible here but what happened to it? is it still in memory somewhere?
}
// and what about here?
someElement.parentNode.removeChild(someElement);