Skip to content

Instantly share code, notes, and snippets.

@andrit
Created July 13, 2018 14:49
Show Gist options
  • Save andrit/dbf28cb96d74d3f22e16b77ff46dc5b7 to your computer and use it in GitHub Desktop.
Save andrit/dbf28cb96d74d3f22e16b77ff46dc5b7 to your computer and use it in GitHub Desktop.
function logAndReturn(func) {
  return function() {
    var args = Array.prototype.slice.call(arguments);
    var result = func.apply(null, args);
    console.log('Result', result);
    return result;
  }
}

function add(x, y){
  return x + y;
  }
  
const addAndLog = logAndReturn(add);
addAndLog(3, 4) //returns 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment