Question

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.

Was it helpful?

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top