Skip to content

Instantly share code, notes, and snippets.

Last active Apr 5, 2016
What would you like to do?
Javascript override method only once wrapper function
function overrideOnce(object, method, callback){
// override method with original as argument
object[method] = (function(original){
return function(){
// store whatever callback does
var result = callback.apply(this, arguments);
// restore method
object[method] = original;
return result;
// usage
overrideOnce(document, 'write', function(html){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment