cujojs/meld

getting handle of before() inside before() body

Closed this issue · 3 comments

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?

@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?

Nevermind, solved is in another way. Thanks.

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