Skip to content

Instantly share code, notes, and snippets.

@rickcnagy
Created June 9, 2014 21:55
Show Gist options
  • Save rickcnagy/d9ea99c33cbc8b548f31 to your computer and use it in GitHub Desktop.
Save rickcnagy/d9ea99c33cbc8b548f31 to your computer and use it in GitHub Desktop.
Extend an existing function. Great for writing code on top of existing systems.
function extend(oldFunc, newFunc, callAfter) {
callAfter = callAfter || true;
if (callAfter) {
return function() {
var ret = oldFunc.apply(this, arguments);
newFunc.apply(this, arguments);
return ret;
}
} else {
return function() {
newFunc.apply(this, arguments);
return oldFunc.apply(this, arguments);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment