Last active
December 11, 2015 10:38
-
-
Save vorporeal/4588364 to your computer and use it in GitHub Desktop.
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
function browserVersionOf(unprefixedName, parentObject) { | |
// parentObject is optional and usually omitted, set it to window if it's not specified. | |
parentObject = parentObject || window; | |
var baseName = unprefixedName.charAt(0).toUpperCase() + unprefixedName.substring(1); | |
var i = 0, variants = [unprefixedName, 'webkit', 'moz', 'ms', 'o']; | |
var fullName = variants[0]; | |
do { | |
if (typeof parentObject[fullName] == 'function') { | |
return parentObject[fullName]; | |
} | |
fullName = variants[++i] + baseName; | |
} while (variants[i]); | |
throw "Browser lacks support for " + unprefixedName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment