Skip to content

Instantly share code, notes, and snippets.

@felixzapata
Created August 21, 2014 07:50
Show Gist options
  • Save felixzapata/4089eb567c0929e688bd to your computer and use it in GitHub Desktop.
Save felixzapata/4089eb567c0929e688bd to your computer and use it in GitHub Desktop.
Extending JavaScript Functions
// http://jondavidjohn.com/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