DCL

An elegant OOP with mixins + AOP for JavaScript.

advise.before()

Version 2.x

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

Description

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

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

It means that instead of:

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

It is possible to write a shorter version:

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

Advice function

This type of advice is a regular function. It is called with the same context and the same arguments as an advised method. Its return value is ignored.

It is not recommended to modify parameters inside before advice. Use after or around advice for that.

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().