四好公路
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

55 lines
825 B

/*!
*
* before
*
* before decorator factory
*
* MIT
*
*/
/**
* Module dependencies.
*/
var slice = [].slice;
/**
* Expose `before`.
*/
module.exports = before;
/**
* Captures `context` to be used by decorator.
*
* @param {Object} [context]
* @return {Function}
* @api public
*/
function before(context){
return decorator;
/**
* Decorates `method` using `outer`.
*
* @param {Function} outer
* @return {Object} this
* @api public
*/
function decorator(method, outer){
var inner = context[method];
context[method] = function(){
var args = slice.call(arguments);
var fn = args[args.length - 1];
return outer.call(context, args, function(err){
if (err) return fn(err);
inner.apply(context, args);
});
};
return this;
}
}