Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A function that replicates the familiar javascript fallback functionality for jquery objects (which are truthy).
var fallback = function(options){
var numOfOptions = options.length;
if (numOfOptions == 2){
return (options[0].length > 0)? options[0] : options[1];
}else if (numOfOptions > 2){
return fallback(options.slice(1));
}else if (numOfOptions == 1){
return options[0];
}else{
return $();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment