Skip to content

Instantly share code, notes, and snippets.

@arxpoetica
Forked from rwaldron/raf.js
Created April 7, 2013 15:53
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 arxpoetica/5331027 to your computer and use it in GitHub Desktop.
Save arxpoetica/5331027 to your computer and use it in GitHub Desktop.
var rAF = "equestAnimationFrame";
window["r"+rAF] = window["r"+rAF] ||
window["webkitR"+rAF] ||
window["mozR"+rAF] ||
window["msR"+rAF] ||
window["oR"+rAF];
// A list
[ "r", "webkitR", "mozR", "msR", "oR", "" ].join( rAF + "," ).split( "," )
// Best one yet:
[ "r", "webkitR", "mozR", "msR", "oR" ].reduce(function( p, v ) {
return window[ v + p ] || p;
}, "equestAnimationFrame");
["r","webkitR","mozR","msR","oR"].reduce(function(p, v) { return window[v + p] || p; }, "equestAnimationFrame");
// Alternate approach ideas
var suffix = "equestAnimationFrame",
rAF = [ "r", "webkitR", "mozR", "msR", "oR" ].filter(function( val ) {
return val + suffix in window;
})[ 0 ] + suffix;
/*
var suffix="equestAnimationFrame",rAF=["r","webkitR","mozR","msR","oR"].filter(function(a){return a+suffix in window})[0]+suffix;
Original Size: 179 bytes (164 bytes gzipped)
Compiled Size: 129 bytes (131 bytes gzipped)
Saved 27.93% off the original size (20.12% off the gzipped size)
*/
var prefix = function( window ) {
var raf = "equestAnimationFrame",
idx;
for ( var prop in window ) {
idx = prop.indexOf( raf );
if ( idx > -1 ) {
return prop.slice( 0, idx - 1 );
}
}
return null;
}( this );
/*
var prefix=function(c){var a,b;for(b in c)if(a=b.indexOf("equestAnimationFrame"),a>-1)return b.slice(0,a-1);return null}(this);
Original Size: 232 bytes (184 bytes gzipped)
Compiled Size: 127 bytes (130 bytes gzipped)
Saved 45.26% off the original size (29.35% off the gzipped size)
*/
console.log(
prefix
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment