Skip to content

Instantly share code, notes, and snippets.

@neomatrixcode
Forked from deleteman/using-aop.js
Created April 10, 2021 15:21
Show Gist options
  • Save neomatrixcode/91725af70aa856942a1fc818426557d8 to your computer and use it in GitHub Desktop.
Save neomatrixcode/91725af70aa856942a1fc818426557d8 to your computer and use it in GitHub Desktop.
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