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);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s