Design & Download
Your JS Library
in Seconds!!!

Snippet: reParam()

Written by Christopher West (cwest) on November 29, 2015.
Creates a wrapper function which when called reorganizes the parameters and then calls the wrapped function.
function reParam(callback, arrFields) {
  arrFields = arrFields.slice();
  for (var len = arrFields.length, i = len; i--;) {
    arrFields[i] = (arrFields[i] + '').split('.');
  }
  return function() {
    for (var args = arguments, arr = [args], i = len; i--;) {
      for (var part = args, parts = arrFields[i], pLen = parts.length, j = 0; j < pLen && part != undefined; j++) {
        part = part[parts[j]];
      }
      arr.unshift(part);
    }
    return callback.apply(this, arr);
  };
}

reParam(...) API Documentation

Creates a wrapper function which when called reorganizes the parameters and then calls the wrapped function.

Parameters

  1. callback {Function}:
    The function to be wrapped.
  2. arrFields {Array.<string>}:
    Array of paths to values that should be passed to callback.

Returns

The wrapper function of callback.