Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created July 17, 2013 06:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save WebReflection/6018078 to your computer and use it in GitHub Desktop.
Save WebReflection/6018078 to your computer and use it in GitHub Desktop.
a very simple and cross platform way to grab some experimental function
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;
}
@WebReflection
Copy link
Author

// example
var requestAnimationFrame = findOrFallback(
  window, 'requestAnimationFrame', function(fn){
    return setTimeout(fn, 1000 / 60);
  }
);

If you are looking for a more complete features finder, check experimental out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment