DCL

An elegant OOP with mixins + AOP for JavaScript.

advise.around()

Version 2.x

This is a convenience function to weave an around advice based on advise().

Description

This is a shortcut function to weave one around advice with an object’s method. Logically it is defined as:

dcl.around()
1
2
3
4
5
advise.around = function(object, name, advice){
  return advise(object, name, {
    around: advice
  });
};

It means that instead of:

Long
1
2
3
var adv = advise(object, name, {
  around: advice
});

It is possible to write a shorter version:

Short
1
var adv = advice.around(object, name, advice);

Advice function

Essentially it is the same as dcl.superCall(), but applied dynamically to an object. It uses the same double function pattern, and its behavior is the same.

Returned value

Just like advise() it is based on, it returns the object, which defines the method unadvise(). When called without parameters, it removes the corresponding advice from the object, no matter when it was defined. For convenience, this method is aliased as remove(), and destroy().

Notes

Don’t forget that around advices always follow the double function pattern:

Around advice
1
2
3
function aroundAdvice (sup) {
  return function (...) {...};
}

See details in dcl.superCall(), dcl.advise(), and advise().