I came across this code while trying to understand how the JavaScript engine interprets wrapper functions. I want to know what are the steps the engine takes when it executes wrapper function code and i want to know what the this refers to in the context of a wrapped function when it is passed around to another variable that executes it later.
function profile(func, funcName) {
       return function () {
    var start = new Date(),
      returnVal = func.apply(this, arguments),
      end = new Date(),
      duration = stop.getTime() - start.getTime();
    console.log(`${funcName} took ${duration} ms to execute`);
    return returnVal;
  };
}
var profiledMax = profile(Math.max, 'Math.max');
profiledMax.call(Math, 1, 2);
