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.
And yes you can have a nested array of functions. If some crazy reason you wanted to do this:
/****
@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 () {
//do something else
},
function () {
//do something elsewhere
}
],
function () {
//do something lastly
}
]