Search code examples
javascriptdojoaspect

dojo/aspect's before()/after() once()?


dojo/on has once() which is extremely useful. How to implement such behaviour in dojo/aspect's before()/after()? I can't believe somebody implemented once() to dojo/on but not dojo/aspect. I don't see any difference.


Solution

  • is it so difficult to save the return of before/after and call remove on it? Here's a simple implementation :

    aspect.onceAfter: function(target, methodName, advice, receiveArguments){
      var handle = aspect.after(target, methodName, function(){
        handle.remove();
        advice.apply(null, arguments);
      }, receiveArguments);
    }