Small but helpfull.
function getFirstDefined(/* ... */) { for (var i=0; i<arguments.length; i++) { if(!isUndefinedOrNull(arguments[i])) return arguments[i]; } /* at least one argument should be defined but ... */ return arguments[length-1]; //return last argument if all isUndefinedOrNull };
Can you add it to Mochikit.Base ;)
When I create an Object with optional parameters:
function myObject(required, /* optional */ options) { /* now you have to write something like this */ if (!(typeof(options['optParam']) == 'undefined' || options['optParam'] == null)) { this.optParam = 'defaultValue'; } else { this.optParam = options['optParam']; } /* why not? */ this.optParam = getFirstDefined(options['optParam'], 'defaultValue'); }
or I'm doing something wrong? ;)
(forgive me my English skills)
