getting handle of before() inside before() body
Closed this issue · 3 comments
0xgeert commented
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
@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
Nevermind, solved is in another way. Thanks.
briancavalier commented
Ok, cool, glad to hear you have a solution.