My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
UsageExample  
Updated Feb 4, 2010 by roman.po...@gmail.com
// Example business logic

var thing = {
  makeGreeting: function(text) {
    return 'Hello ' + text + '!';
  }
}

alert(thing.makeGreeting('world')); // Hello world!


// Advice definitions

function aopizeAdvice(args) {
  args[0] = 'AOP ' + args[0];
  return args;
}

function shoutAdvice(result) {
  return result.toUpperCase();
}

function ciaoAdvice() {
  return 'Bye-bye!';
}


// Adding advices

Ajaxpect.addBefore(thing, 'makeGreeting', aopizeAdvice);
alert(thing.makeGreeting('world')); // Hello AOP world!

Ajaxpect.addAfter(thing, /make*/, shoutAdvice);
alert(thing.makeGreeting('world')); // HELLO AOP WORLD!

var filter = function(name) { return name.indexOf('Greet') != -1 }
Ajaxpect.addAround(thing, filter, ciaoAdvice);
alert(thing.makeGreeting('world')); // Bye-bye!
Comment by mail.r...@gmail.com, Sep 5, 2007

hi

Comment by clony...@gmail.com, Jan 9, 2008

smallest AOP implementation ever!

Comment by intrader.intrader@gmail.com, May 1, 2009

Clear, concise, and elegant. I would like to see exception, and introduction advises


Sign in to add a comment
Powered by Google Project Hosting