Created
June 19, 2012 10:57
-
-
Save WebReflection/2953527 to your computer and use it in GitHub Desktop.
process.nextTick(callback) for browsers too
This file contains hidden or 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 (window) {"use strict"; | |
// by WebReflection - WTFPL License | |
var | |
prefixes = "r webkitR mozR msR oR".split(" "), | |
process = "process", | |
nextTick = "nextTick", | |
i = 0, | |
p = window[process] || (window[process] = {}) | |
; | |
while (!p[nextTick] && i < prefixes.length) | |
p[nextTick] = window[prefixes[i++] + "equestAnimationFrame"] | |
; | |
p[nextTick] || (p[nextTick] = window.setImmediate || window.setTimeout); | |
}(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this, but I had a few problems with it.
First, adding any of the window functions onto
process
causes an illegal invocation, at least in chrome. To fix this you have to bind it back to the window. My version usesbind
so is probably not backwards compatible, but works for me.Second a note on using
this
as a way to minify forwindow
. If you use a build tool like browserify to wrap this it will break because it wraps everything in a closure.To fix that issue while still remaining small I made a few modifications:
With the additional bind fix and changing
this
towindow
the original is 245 bytes. This one with both fixes is 219 bytes. I tested both with this script and they seemed to work: