I'm trying to look up best practices and techniques for functions that accept "mixed" variables. This is similar to how the jQuery object accepts string, objects, and HTML Elements, and intelligently figures out what to do.
But I'm not sure what this pattern is called. How would a knowledgeable JavaScript developer refer to this technique?
For example:
function formatParams(mixed) {
var params = {};
switch (typeof mixed) {
case 'string' :
params = {query: mixed};
break;
case 'number' :
params = {id: mixed};
break;
case 'function' :
params = {callback: mixed}
break;
default:
params = mixed;
}
return params;
}