Consider this JavaScript code...
(function() {
window.myNameSpace_callback = function() {
// Do whatever.
delete window.myNameSpace_callback;
};
// Assume this does not return JSON, but has JavaScript code to be executed
// and also calls a user defined callback.
$.getScript('http://someapi.com/?callback=myNameSpace_callback');
})();
The fact I used the jQuery library above should be irrelevant to the question.
After the delete
line, the global does not exist. I'm doing this to keep this global only alive for as long as it has to be.
However, is it bad practice to delete a property from the global object which happens to be the current running function?