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
Get it using one of the following
yeoman install meld
, orbower install meld
, orgit clone https://github.com/cujojs/meld
, orgit 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, ...) { ... });
or require(['meld', ...], function(meld, ...) { ... });
npm install meld
var meld = require('meld');
ringo-admin install cujojs/meld
var meld = require('meld');
Install buster.js
npm install -g buster
Run unit tests in Node:
buster test
meld()
is now a function that adds aspects.
meld.add()
. Use meld()
instead.console.log
.Object.defineProperty
.meld.joinpoint()
- Access the current joinpoint from any advice type.window.meld
is no longer supported. See this post on the cujo.js Google Group for an explanation.See the full Changelog here