Skip to content

Instantly share code, notes, and snippets.

@SebastianHGonzalez
Last active January 1, 2019 16:51
Show Gist options
  • Save SebastianHGonzalez/10c3ffb11f14cf92c54b47752eac84f9 to your computer and use it in GitHub Desktop.
Save SebastianHGonzalez/10c3ffb11f14cf92c54b47752eac84f9 to your computer and use it in GitHub Desktop.
second try at AOP
function loggerAspect(joinPoint, logger) {
return function (...args) {
logger.log("logging");
return joinPoint.apply(this, args)
}
}
const psyduck = {
sound: "PSYDUCK!",
cuack: function() {return this.sound}
}
psyduck.cuack();
// <- "PSYDUCK!"
// Apply the logger aspect to cuack method
psyduck.cuack = loggerAspect(psyduck.cuack, console);
psyduck.cuack()
// logging
// <- "PSYDUCK!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment