Skip to content

Instantly share code, notes, and snippets.

@jondavidjohn
Last active December 30, 2015 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jondavidjohn/7791785 to your computer and use it in GitHub Desktop.
Save jondavidjohn/7791785 to your computer and use it in GitHub Desktop.
How to extend JavaScript functions
Array.prototype.join = (function(_super) {
// return our new `join()` function
return function() {
console.log("Hey, you called join!");
return _super.apply(this, arguments);
};
// Pass control back to the original join()
// by using .apply on `_super`
})(Array.prototype.join);
//
// Pass the original function into our
// immediately invoked function as `_super`
// which remains available to our new
// function thanks to JavaScript Closures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment