how do you delay a function to the next tick in javascript?
back
3 comments
That phrasing isn't very precise, but I presume they mean to use setTimeout and pass a timeout of 0 [0]. That link has some discussion of this use and suggests using window.postMessage instead, at least on "modern browsers", for a suitable definition of modern.
Im assuming we are talking client-side and 'next tick' means when there is a millisecond of free time. Just use: setTimeout(function, 0)
Technically supplying '0' as the milliseconds is bad in old browsers, so you might want to say 10...but I've used '0' a lot without fail.
setTimeout(fn, 0);