├── index.js ├── package.json └── README.md /index.js: -------------------------------------------------------------------------------- 1 | module.exports = (function(window, prefixes, i, p, fnc, to) { 2 | while (!fnc && i < prefixes.length) { 3 | fnc = window[prefixes[i++] + 'equestAnimationFrame']; 4 | } 5 | return (fnc && fnc.bind(window)) || window.setImmediate || function(fnc) {window.setTimeout(fnc, 0);}; 6 | })(typeof window !== 'undefined' ? window : global, 'r webkitR mozR msR oR'.split(' '), 0); 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "browser-next-tick", 3 | "version": "1.1.0", 4 | "description": "A very small implementation of process.nextTick for the browser using requestAnimationFrame", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/wesleytodd/browser-next-tick.git" 12 | }, 13 | "author": "Wes Todd", 14 | "license": "ICS" 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `process.nextTick` for the browser 2 | 3 | This can be used as either a `process.nextTick` implementation or a `window.requestAnimationFrame` polyfill. 4 | 5 | Usage: 6 | 7 | ```javascript 8 | 9 | var nextTick = require('browser-next-tick'); 10 | 11 | nextTick(function() { 12 | // Will be run on next available event loop 13 | }); 14 | ``` 15 | 16 | Actual source: 17 | 18 | ```javascript 19 | module.exports = (function(window, prefixes, i, p, fnc) { 20 | while (!fnc && i < prefixes.length) { 21 | fnc = window[prefixes[i++] + 'equestAnimationFrame']; 22 | } 23 | return (fnc && fnc.bind(window)) || window.setImmediate || function(fnc) {window.setTimeout(fnc, 0);}; 24 | })(window, 'r webkitR mozR msR oR'.split(' '), 0); 25 | ``` 26 | --------------------------------------------------------------------------------