Self destructing Javascript function - How does it work?
问题 So I found this piece of code and it obviously works (as it has been in production for years): window[someMethod] = function (tmp) { callback({prop:"val"}, tmp); // Garbage collect window[someMethod] = undefined; try { delete window[someMethod]; } catch (e) { } if (head) { head.removeChild(script); } // head refers to DOM head elem and script refers to some script file elem }; Curious to know, how does it work? How can it set itself to undefined within its body and try to delete itself? Does