function decorate (baseFunction, decoratorFunction) {
return function () {decoratorFunction(baseFunction, arguments);};
}
function a (a) {
console.log(a);
return 'OK';
}
function b (baseFunction, baseFunctionArguments) {
console.log('start');
baseFunction.apply(null, baseFunctionArguments);
console.log('b');
console.log('stop');
}
a = decorate(a, b);
a('a');
function trace (baseFunction, baseFunctionArguments) {
var result = baseFunction.apply(null, baseFunctionArguments);
console.log('TRACE: ' + baseFunction.name + ' (' + Array.prototype.slice.call(baseFunctionArguments).join(', ') + ') => ' + result);
return result;
}
var c = decorate(a, trace);
c('a', 'b', 1, 2, {});
Комментариев нет:
Отправить комментарий