Created
August 21, 2014 07:50
-
-
Save felixzapata/4089eb567c0929e688bd to your computer and use it in GitHub Desktop.
Extending JavaScript Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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