Aspect Oriented Programming for Javascript. It allows you to change the behavior of, or add behavior to methods and functions (including constructors) non-invasively.
As a simple example, instead of changing code, you can use meld to log the result of myObject.doSomething:
var myObject = {
doSomething: function(a, b) {
return a + b;
}
};
// Call a function after myObject.doSomething returns
var remover = meld.after(myObject, 'doSomething', function(result) {
console.log('myObject.doSomething returned: ' + result);
});
myObject.doSomething(1, 2); // Logs: "myObject.doSomething returned: 3"
remover.remove();
myObject.doSomething(1, 2); // Nothing logged-
git clone https://github.com/cujojs/meldorgit submodule add https://github.com/cujojs/meld -
Configure your loader with a package:
packages: [ { name: 'meld', location: 'path/to/meld', main: 'meld' }, // ... other packages ... ]
-
define(['meld', ...], function(meld, ...) { ... });orrequire(['meld', ...], function(meld, ...) { ... });
git clone https://github.com/cujojs/meldorgit submodule add https://github.com/cujojs/meld<script src="https://redirect.github.com/path/to/meld/meld.js"></script>meldwill be available aswindow.meld
npm install meldvar meld = require('meld');
ringo-admin install cujojs/meldvar meld = require('meld');
Install buster.js
npm install -g buster
Run unit tests in Node:
buster test -e node
Run unit tests in Browsers (and Node):
buster server- this will print a url- Point browsers at /capture, e.g.
localhost:1111/capture buster testorbuster test -e browser
- Fix for context when advising constructors:
thisis now the constructed instance in all advice functions.
- Fix for global name when using meld as a browser global. Thanks @scothis
- Update unit tests to run in browser using
buster server, in addition to node. Thanks again, @scothis :)
- Advice can be applied directly to functions without a context.
- Advice can be applied to constructors.
joinpoint.proceed()can be called multiple times. This makes it possible to implement "retry" types of advice.
- aop.js is now meld.js
- Use Travis CI
- Optimizations to run time advice invocation, especially around advice
- Fix for passing new args to
joinpoint.proceed()in around advice - Added
joinpoint.proceedApply(array)for proceeding and supplying new arguments as an array - Ported unit tests to BusterJS
- First official release as part of cujojs
- Minor doc and package.json tweaks
- Revert to larger, more builder-friendly module boilerplate. No functional change.
- Minor corrections and updates to
package.json
- Rewritten Advisor that allows entire aspects to be unwoven (removed) easily.
- AspectJ and Spring Framework AOP for inspiration and great docs
- Implementation ideas from @phiggins42's uber.js AOP
- API ideas from jquery-aop
