Description
I have a function that passes the options parameter. This parameter can be an object , an array, or a string . Depending on what the parameter will determine what to do.
UPDATE: I forgot to mention that options should always end up as an object of the same structure (in other words, it should always set default values).
I only want to determine the default values ββonce, so using the if procedural instructions, as some of you have suggested, is not my preferred solution, but will resort to it if necessary.
I do not want to do this (if possible):
function foo(options){ switch(typeof options){ case 'string':
Example
If the parameter is an object, then expand it to set default values ββas follows:
function foo(options){
If the parameter is a string, set options.bar to a string and expand the default values ββ(something like this):
function foo(options){
If the parameter is an array, set options.baz equal to the array and extend the default values ββ(something like this):
function foo(options){
Question
Thus, I want to be able to specify the parameter in any format, and the function will build the same options object from what was provided. If no values ββare specified, they resort to their default values.
Sorry, this is so incomprehensible, it is very difficult to explain.
Additional example
Another potential way I can demonstrate (jQuery) is to look at a function like animate () . Please note that you can either put:
.animate( properties [, duration] [, easing] [, complete] )
or
.animate( properties, options )
This additional example is not exactly what I hope to achieve, but it is on the right line.