Skip to content

Instantly share code, notes, and snippets.

@SebastianHGonzalez
Created January 1, 2019 16:13
Show Gist options
  • Save SebastianHGonzalez/9ecd08f845cb9a173b40ce5bd7b3c2a9 to your computer and use it in GitHub Desktop.
Save SebastianHGonzalez/9ecd08f845cb9a173b40ce5bd7b3c2a9 to your computer and use it in GitHub Desktop.
Aspects applied to instance methods
function loggerAspect(joinPoint, logger) {
return function (...args) {
logger.log("logging");
return joinPoint.apply(this, args)
}
}
class Person {
constructor(name) {
this.name = name
}
greeting() {
return "Hello " + this.name
}
}
const person = new Person("john doe");
person.greeting();
// <- "Hello john doe"
// Apply logger aspect
Person.prototype.greeting = loggerAspect(Person.prototype.greeting, console)
person.greeting();
// logging
// <- "Hello john doe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment