Skip to content

Instantly share code, notes, and snippets.

@JemarJones
Created July 7, 2015 01:36
Show Gist options
  • Save JemarJones/9ad6fc28cd3ba6bac459 to your computer and use it in GitHub Desktop.
Save JemarJones/9ad6fc28cd3ba6bac459 to your computer and use it in GitHub Desktop.
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