Say you have [Fiddle]
function TestMethod() {
var lifespan = "blah";
$.ajax({
url: "http://www.google.com",
success: function (data) {
alert(lifespan);
},
error: function (errorData) {
alert(lifespan);
},
dataType: 'html'
});
}
Why is it that lifespan still exists when the callback fires? What else persists through asynchronous calls? What allows this to happen, is there some kind of "runtime" ,if you will, in javascript that keeps code alive during the process? If so, when does it know when to start letting in memory items die?