Skip to content

Instantly share code, notes, and snippets.

@Integralist
Forked from WebReflection/find-or-fallback.js
Last active December 19, 2015 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/6018869 to your computer and use it in GitHub Desktop.
Save Integralist/6018869 to your computer and use it in GitHub Desktop.
JavaScript function that lets you query for the API or provide a fallback if not available
function findOrFallback(where, what, fallback) {
for(var
vendors = ['', 'webkit', 'moz', 'ms', 'o'],
first = what.charAt(0),
others = first.toUpperCase(),
suffix = what.slice(1),
i = 0, length = vendors.length,
current;
i < length; i++
) {
current = where[vendors[i] + (i ? others : first) + suffix];
if (current) return current;
}
return fallback;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment