cujojs / meld

AOP for JS with before, around, on, afterReturning, afterThrowing, after advice, and pointcuts
Other
644 stars 65 forks source link

getting handle of before() inside before() body #15

Closed 0xgeert closed 11 years ago

0xgeert commented 11 years ago

Given (from the docs) var remover = meld.before(object, match, beforeFunction);

Is there a way to get a handle to 'remover' in the body of beforeFunction?

briancavalier commented 11 years ago

@gbrits There's no way to access the remover from the joinpoint. The reasoning is that the remover should primarily be available to the code that adds the advice.

If you need to create self-removing advice, one option would be to capture the remover:

var remover = meld.before(object, 'method', function(/* args */) {
    // Remove myself
    remover.remove();

    // do other things here, for example
    beforeFunction.apply(null, arguments);
});

Will that work for you?

0xgeert commented 11 years ago

Nevermind, solved is in another way. Thanks.

briancavalier commented 11 years ago

Ok, cool, glad to hear you have a solution.