Uses ES6 Proxy to instrument JS in an (unfortunately too verbose) aspect-oriented way
$ npm install --save javascript-proxy-aop
const javascriptProxyAop = require('javascript-proxy-aop');
// pubSub may be any object that supports trigger
const instrument = javascriptProxyAop(pubSub);
const obj = instrument({
method: function() {},
anotherMethod: function fooBar() {}
});
obj.method(['hello', 'world']);
// => pubSub.on('onBeforeMethod', method, args) is called
// => method: 'anonymous<method>'
// => args: [['hello', 'world']]
// => pubSub.on('onAfterMethod', method, args) is called
// => method: 'anonymous<method>'
// => args: [['hello', 'world']]
// => result: undefined
obj.anotherMethod(); // method is 'fooBar'
- enable to instrument functions directly
MIT © Daniel Schmidt