https://github.com/danielmschmidt/javascript-proxy-aop
AOP through Proxies
https://github.com/danielmschmidt/javascript-proxy-aop
Last synced: over 1 year ago
JSON representation
AOP through Proxies
- Host: GitHub
- URL: https://github.com/danielmschmidt/javascript-proxy-aop
- Owner: DanielMSchmidt
- License: mit
- Created: 2016-05-22T18:49:40.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-05-22T07:35:23.000Z (about 8 years ago)
- Last Synced: 2025-02-22T12:38:05.688Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# javascript-proxy-aop [](https://travis-ci.org/DanielMSchmidt/javascript-proxy-aop) [](https://coveralls.io/github/DanielMSchmidt/javascript-proxy-aop?branch=master)
> Uses ES6 Proxy to instrument JS in an (unfortunately too verbose) aspect-oriented way
## Install
```
$ npm install --save javascript-proxy-aop
```
## Usage
```js
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'
// => args: [['hello', 'world']]
// => pubSub.on('onAfterMethod', method, args) is called
// => method: 'anonymous'
// => args: [['hello', 'world']]
// => result: undefined
obj.anotherMethod(); // method is 'fooBar'
```
## TODO
- [ ] enable to instrument functions directly
## License
MIT © [Daniel Schmidt](http://danielmschmidt.de)