Javascript function accepts both arrays and strings as parameter -


i have code:

    var showregion = function(key) {         if (key in regionoptions) {             var entry       = regionoptions[key];             var builder     = entry.builder;             var layoutobj   = entry.layoutobj;             var viewstarter = entry.viewstarter;              var view = new builder();             logger.info('controller.' + key + ' => createaccountlayoutcontroller');             controller.layout[layoutobj].show(view);             view[viewstarter]();         }     }; 

what need parameter should able accept array or string, , should work either way.

sample function calls:

showregion('phonenumberregion'); showregion(['phonenumberregion', 'keyboardregion', 'nextregion']); 

var showregion = function(key) {     if (typeof key === 'string')          key = [key];     if (key in regionoptions) {        ... 

no need make code each case, convert key string array of 1 element , code arrays both.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -