Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
HOC, decorating functions
function doSomething(name) {
console.log('hello ' + name);
function loggingDecorator(wrappedFunction) {
return function() {
const result = wrappedFunction.apply(this, arguments);
return result;
const wrapped = loggingDecorator(doSomething);
doSomething('paul'); // 'hello paul'
wrapped('paul'); // 'starting', 'hello paul', 'finished'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment