Close

Faster way of passing a param to call functions.

This pattern of functions as objects runs significantly faster than a switch statement doing the same thing on IE (40%) and marginally faster on Chrome (15%) and Firefox (3%) however safari actually comes in faster with optimisations on switch statements by 1.8%.

For SharePoint at least this is worth considering as a pattern for any large switch statement you may use.

var opt = "example";

var funcCalls = {
  "Add":addToFunction = function(options) {
    alert("Zero " + options);
  },
  "Add1":addToFunction1 = function(options) {
    alert("One " + options);
  },
  "Add2":addToFunction2 = function(options) {
    alert("Two " + options);
  },
  "Add3":addToFunction3 = function(options) {
    alert("Three " + options);
  }
};

myCall = "Add1";
funcCalls[myCall].call(this, opt);
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *

© Hugh Wood 1980-Present