Skip to content

Instantly share code, notes, and snippets.

@ahomu
Created July 22, 2012 03:30
Show Gist options
  • Save ahomu/3158258 to your computer and use it in GitHub Desktop.
Save ahomu/3158258 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