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; | |
| } |
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 function (...args) { | |
| logger.log("logging"); | |
| return joinPoint.apply(this, args) | |
| } | |
| } | |
| const psyduck = { | |
| sound: "PSYDUCK!", | |
| cuack: function() {return this.sound} |
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 function (...args) { | |
| logger.log("logging"); | |
| return joinPoint.apply(this, args) | |
| } | |
| } | |
| class Person { | |
| constructor(name) { | |
| this.name = name |
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 aspect(joinPoint, { before, around, after }) { | |
| return function (...args) { | |
| before && before(this, joinPoint.name, ...args); | |
| const result = around ? around(this, joinPoint, ...args) : joinPoint.apply(this, args); | |
| after && after(this, joinPoint.name, result, ...args); | |
| return result; | |
| } | |
| } | |
| function loggerAspect(joinPoint, logger) { |
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 timeAspect(joinPoint, logger) { | |
| const timer = { | |
| start: function () { this.startTime = Date.now() }, | |
| stop: function () { this.stopTime = Date.now() }, | |
| time: function () { return this.stopTime - this.startTime } | |
| }; | |
| function before() { timer.start() } | |
| function after() { timer.stop(), logger.log(timer.time) } | |
| return aspect(joinPoint, { before, after }) |
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 greet() { | |
| return "Hello " + this.name ; | |
| } | |
| const john = { | |
| name: "John" | |
| } | |
| const jane = { | |
| name: "Jane" |
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
| const personGreetingPC = new PointCut({class: Person, methodName: "greet"}); | |
| jhon.greet(); | |
| // <- "Hello jhon" | |
| personGreetingPC.addAspect(loggerAspect); | |
| jhon.greet(); | |
| // logging | |
| // <- "Hello jhon" |
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
| class PointCut { | |
| constructor(definition) { | |
| this.inject(definition); | |
| } | |
| inject(definition) { | |
| this.injectAspectToObjectMethods(definition.class.prototype); | |
| } | |
| injectAspectToObjectMethods(prototype) { |
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 timeAspect(joinPoint, logger) { | |
| const aspect = { | |
| logger, | |
| timer: { | |
| start: function () { this.startTime = Date.now() }, | |
| stop: function () { this.stopTime = Date.now() }, | |
| time: function () { return this.stopTime - this.startTime } | |
| }, | |
| before: function () { this.timer.start() }, |
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
| class LoggerAspect { | |
| constructor(logger) { | |
| this.logger = logger; | |
| } | |
| before(context, joinPointName, ...args) { | |
| this.logger.log("logging"); | |
| } | |
| } |
OlderNewer