Created
November 29, 2020 17:10
-
-
Save deleteman/1efd939193400a569308945eb445e3cd to your computer and use it in GitHub Desktop.
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
const AOP = require("./aop.js") | |
class MyBussinessLogic { | |
add(a, b) { | |
console.log("Calling add") | |
return a + b | |
} | |
concat(a, b) { | |
console.log("Calling concat") | |
return a + b | |
} | |
power(a, b) { | |
console.log("Calling power") | |
return a ** b | |
} | |
} | |
const o = new MyBussinessLogic() | |
function loggingAspect(...args) { | |
console.log("== Calling the logger function ==") | |
console.log("Arguments received: " + args) | |
} | |
function printTypeOfReturnedValueAspect(value) { | |
console.log("Returned type: " + typeof value) | |
} | |
AOP.inject(o, loggingAspect, "before", "methods") | |
AOP.inject(o, printTypeOfReturnedValueAspect, "afterReturning", "methods") | |
o.add(2,2) | |
o.concat("hello", "goodbye") | |
o.power(2, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment