function meld(target, pointcut, aspect) { var pointcutType, remove; if(arguments.length < 3) { return addAspectToFunction(target, pointcut); } else { if (isArray(pointcut)) { remove = addAspectToAll(target, pointcut, aspect); } else { pointcutType = typeof pointcut; if (pointcutType === 'string') { if (typeof target[pointcut] === 'function') { remove = addAspectToMethod(target, pointcut, aspect); } } else if (pointcutType === 'function') { remove = addAspectToAll(target, pointcut(target), aspect); } else { remove = addAspectToMatches(target, pointcut, aspect); } } return remove; } }
n/a
add = function () { return meld.apply(null, arguments); }
...
`buster test`
# What's New
### 1.3.0
* [`meld()`](docs/api.md#adding-aspects) is now a function that adds aspects.
* **DEPRECATED:** `meld.add()`. Use `meld()` instead.
### 1.2.2
* Remove stray `console.log`.
### 1.2.1
...
after = function (target, method, adviceFunc) { var aspect = {}; if(arguments.length === 2) { aspect[type] = method; return meld(target, aspect); } else { aspect[type] = adviceFunc; return meld(target, method, aspect); } }
...
var myObject = {
doSomething: function(a, b) {
return a + b;
}
};
// Call a function after myObject.doSomething returns
var remover = meld.after(myObject, 'doSomething', function(result) {
console.log('myObject.doSomething returned: ' + result);
});
myObject.doSomething(1, 2); // Logs: "myObject.doSomething returned: 3"
remover.remove();
...
afterReturning = function (target, method, adviceFunc) { var aspect = {}; if(arguments.length === 2) { aspect[type] = method; return meld(target, aspect); } else { aspect[type] = adviceFunc; return meld(target, method, aspect); } }
n/a
afterThrowing = function (target, method, adviceFunc) { var aspect = {}; if(arguments.length === 2) { aspect[type] = method; return meld(target, aspect); } else { aspect[type] = adviceFunc; return meld(target, method, aspect); } }
n/a
around = function (target, method, adviceFunc) { var aspect = {}; if(arguments.length === 2) { aspect[type] = method; return meld(target, aspect); } else { aspect[type] = adviceFunc; return meld(target, method, aspect); } }
n/a
before = function (target, method, adviceFunc) { var aspect = {}; if(arguments.length === 2) { aspect[type] = method; return meld(target, aspect); } else { aspect[type] = adviceFunc; return meld(target, method, aspect); } }
n/a
function joinpoint() { return currentJoinpoint; }
...
### 1.2.1
* Fix for IE8-specific issue with meld's internal use of `Object.defineProperty`.
* Internally shim Object.create if not available to so that meld no longer requires an Object.create shim to advise constructors
in pre-ES5 environments.
### 1.2.0
* `meld.joinpoint()` - [Access the current joinpoint](docs/api.md#meldjoinpoint) from
any advice type.
* [Bundled aspects](docs/aspects.md):
* trace: trace method call entry/return/throw
* memoize: simple memoization for methods and functions
* cache: configurable caching aspect to do more than simple memoization
### 1.1.0
...
on = function (target, method, adviceFunc) { var aspect = {}; if(arguments.length === 2) { aspect[type] = method; return meld(target, aspect); } else { aspect[type] = adviceFunc; return meld(target, method, aspect); } }
n/a