Skip to content

Instantly share code, notes, and snippets.

@shuuheyhey
Forked from ahomu/detectVendorFunction.js
Created May 21, 2013 19:58
Show Gist options
  • Save shuuheyhey/5622737 to your computer and use it in GitHub Desktop.
Save shuuheyhey/5622737 to your computer and use it in GitHub Desktop.
ベンダープレフィックス決めるくん.js
function detectVendorFunction(object, methodName) {
var upperName = methodName.charAt(0).toUpperCase()+methodName.substr(1),
detectedMethod;
detectedMethod = object[methodName] ||
object['webkit'+upperName] ||
object['moz'+upperName] ||
object['ms'+upperName] ||
object['o'+upperName];
if (detectedMethod) {
return detectedMethod;
} else {
throw new Error(methodName+' not found in specified object');
}
}
var getUserMedia = detectVendorFunction(navigator, 'getUserMedia');
var requestAnimationFrame = detectVendorFunction(window, 'requestAnimationFrame');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment