I had a colleague ask me why he couldn't access an event parameter from a callback function. Turns out that jquery seems to be setting the event to null after the call finishes and creating a temporary local variable fixed the problem (see below).
Then that got me thinking, why is 'message' even available to the callback. Can someone please explain?
$('some seletor').click({msg: message},function(event){
alert(event.data.msg); //event.data.msg is not available to the json callback because event is null
var message = event.data.msg; //message will be available to the callback...why?
$.getJSON('ajax/test.json', function(data) {
alert(message); //works ok - why is the message variable visible here at all, should it not have gone out of scope when the above function ended?
alert(event.data.msg); //will crash, seems that event has been set to null by the framework after the function finished
});
});