AOP for JS with before, around, on, afterReturning, afterThrowing, after advice, and pointcuts
Clone or download
Latest commit de51e87 Apr 21, 2015

Build Status

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"


myObject.doSomething(1, 2); // Nothing logged


Quick Start


  1. Get it using one of the following

    1. yeoman install meld, or
    2. bower install meld, or
    3. git clone, or
    4. git submodule add
  2. Configure your loader with a package:

    packages: [
    	{ name: 'meld', location: 'path/to/meld', main: 'meld' },
    	// ... other packages ...
  3. define(['meld', ...], function(meld, ...) { ... }); or require(['meld', ...], function(meld, ...) { ... });


  1. npm install meld
  2. var meld = require('meld');


  1. ringo-admin install cujojs/meld
  2. var meld = require('meld');

Running the Unit Tests

Install buster.js

npm install -g buster

Run unit tests in Node:

buster test

What's New


  • meld() is now a function that adds aspects.
    • DEPRECATED: meld.add(). Use meld() instead.


  • Remove stray console.log.


  • Fix for IE8-specific issue with meld's internal use of Object.defineProperty.
  • Internally shim Object.create if not available to so that meld no longer requires an Object.create shim to advise constructors in pre-ES5 environments.


  • meld.joinpoint() - Access the current joinpoint from any advice type.
  • Bundled aspects:
    • trace: trace method call entry/return/throw
    • memoize: simple memoization for methods and functions
    • cache: configurable caching aspect to do more than simple memoization


  • Advice can be applied directly to methods on a function.
  • Removed undocumented behavior that implicitly adds constructor prototype advice: to advise a prototype, pass the prototype as the advice target.


See the full Changelog here