Last active
January 1, 2019 17:11
-
-
Save SebastianHGonzalez/2cba6ebaa61385f05a4834f18102b973 to your computer and use it in GitHub Desktop.
My first try at AOP
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
function loggerAspect(joinPoint, logger) { | |
return (...args) => { | |
logger.log("logging"); | |
return joinPoint(...args); | |
} | |
} | |
function add(a, b) { | |
return a + b; | |
} | |
add(1, 2); | |
// <- 3 | |
add = loggerAspect(add, console); | |
add(1, 2); | |
// logging | |
// <- 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment