Posts

Showing posts from July, 2014

Execute Functions...solo or Array

I have found myself multiple times having to "re-invent" this methodology to execute a single pass-through function or an array, pending on the situation.   For myself, and to share with others, I am posting this code-snippet for consumption. /**** @func - function() or [function(), function(),...] ****/ function ExecuteFunction( func ) { if ( typeof func !== 'undefined' && func != null ) { if ( typeof func === 'function' ) { func(); } else { if ( func instanceof Array ) { func.forEach( function ( fn ) { ExecuteFunction( fn ); } ); } } } } And yes you can have a nested array of functions.  If some crazy reason you wanted to do this: var func = [ function(){ //do something }, [ function () {