A small Aspect Oriented Programming JavaScript library
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Latest commit 944159b Sep 9, 2015
Permalink
Failed to load latest commit information.
LICENSE Initial commit Feb 11, 2014
README.md Minor cleanup README Sep 9, 2015
aop.js Preparation for publishing on npm Feb 20, 2015
package.json 0.1.2 Sep 9, 2015

README.md

AOP

A small Aspect Oriented Programming JavaScript library

How to install

npm install tiny-aop

How to use

In our search for a simple AOP library in JavaScript we evaluated several solutions and decided to use Fredrik Appelberg's excellent Aop.js. We found that instead of passing JavaScript objects into the namespaces parameter we needed to pass an object prototype in, so all instances of our object's methods were intercepted by the aspect. Only a couple of very minor modifications were needed for this, so credit is entirely due here to Fredrik's library. With his kind permission I have published our modified version of the library.

How to use (assume 'cat' objects with prototype 'makeSound'...):

	var Aop = require("tiny-aop");
	
	var Cat = function() {
	  this.makeSound = function() {
	    console.log('Meooowwww!');
	  };
	};
	
	Cat.prototype.test = function() {
		console.log('test-proto');
	}
	
	var test = new Cat;
	
	Aop.before("test", function() {
	      console.log('aop-test', arguments);
	}, [ Cat.prototype ]);
	
	Aop.before("makeSound", function() {
	      console.log('aop-sound', arguments);
	}, [ test ]);
	
	test.makeSound(2, 56);
	test.test();

License: MIT