Created
July 7, 2015 01:36
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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