Last active
January 1, 2019 16:51
-
-
Save SebastianHGonzalez/10c3ffb11f14cf92c54b47752eac84f9 to your computer and use it in GitHub Desktop.
second try at AOP
This file contains 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
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