wrap a JavaScript method with a different method

You can wrap a JavaScript method with another method by utilizing the apply() method and arguments property inside a function.

function wrapMethod(method) {
  var args = [];
  for(var i = 1; i < arguments.length; i++) {
    if(arguments[i] !== undefined) {
      args.push(arguments[i]);
    }
  }

  if(typeof this[method] !== 'undefined') {
    this[method].apply(this, args);
  }
}

You can call the method like this:

this.methodToWrap = function(one, two){
  console.log([one, two]);

...