I am trying to take advantage of Javascript closures by creating a method in one context and storing it in a global variable so that it may be called later from another context.
//Global variable to hold the function
var revertEvent;
//creates the function and assigns it to the global variable
function createRevertFunction(eventToBeReverted) {
revertEvent = function () {
alert("Now Restoring Event");
$('#calendar').fullCalendar('renderEvent', eventToBeReverted, true);
}
}
So, the "createRevertFunction" holds the state of the original object. That object "eventToBeReverted" is modified down the road after this function is called, so this provides a means to restore the original to the UI without page refresh.
My problem is that I can't seem to call the function in the variable "revertEvent".
I've tried:
revertEvent();
revertEvent.call();
window[revertEvent]();
and none of them work. Any help would be appreciated...!