Skip to content

Instantly share code, notes, and snippets.

@jfairbank
Last active November 26, 2017 06:22
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfairbank/b356f676a7956ea0ed95 to your computer and use it in GitHub Desktop.
Save jfairbank/b356f676a7956ea0ed95 to your computer and use it in GitHub Desktop.
JS Wrap
function wrap(orig, newDef) {
return function(...args) {
return newDef.apply(this, [orig].concat(args));
};
}
myLib.getTotal = wrap(myLib.getTotal, function(orig, ...args) {
let total = orig.apply(this, args) * 0.8;
return total + this.getTax();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment