aspectos

Small and simple AOP library

npm install aspectos
2 downloads in the last week
4 downloads in the last month

Aspectos Build Status

A simple library to provide basic AOP (Aspect Oriented Programming) functionality to your scripts.

Cloning

The Jasmine testing framework is used for the tests and is added as a submodule.

You can either clone this repo with the submodules in one command like so:

git clone REPO_URL --recursive

or separately

git clone REPO_URL
<cd clonedrepo>
git submodule update --init --recursive

Usage

Aspectos provides three methods to provide the basic aspects to your objects: before(), after(), around(). These allow you to run other function before, after or around any method respectively.

before

var testObject = {
    write: function() {
        testValue += ' 2';
    }
};
testObject.write = aspectos.before(testObject, 'write', function() {
    testValue += '1';
});
testObject.write();
// should write out '1 2'

after

var testObject = {
    write: function() {
        testValue += '1';
    }
};
testObject.write = aspectos.after(testObject, 'write', function() {
    testValue += ' 2';
});
testObject.write();
// should write out '1 2'

around

var testObject = {
    write: function() {
        testValue += ' ';
    }
};
testObject.write = aspectos.around(
    testObject,
    'write',
    [
        function() {
            testValue += '1';
        },
        function() {
            testValue += '2';
        }
    ]
);
testObject.write();
//should write '1 2'

Tests

See the index.html file in the tests directory

npm loves you