Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

92 lines (66 sloc) 2.24 kb

Aspectos Build Status

A simple library to provide basic AOP (Aspect Oriented Programming) functionality to your scripts. It allows one to decorate methods and functions with behaviours that are run either before, after or around (before and after) the decorated method or function.

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

If you have testem installed run it from the root directory of the repo.

testem

or

testem ci -b Chrome

Mocha tests can be run with phantomjs (note the ci hash parameter):

phantomjs ./lib/test-helpers/run-mocha.js file://localhost/$(pwd)/aspectos/src/tests/index.html#ci
Jump to Line
Something went wrong with that request. Please try again.