Why are some JavaScript developers using setTimeout for one millisecond?
javascript, jquery, settimeout, tablesorter
Solution
It's an old hack. If an event needs to be triggered after another event you can use `setTimeout` with 1ms to make sure the event is triggered after the other event.
Problem
I have problem when using jQuery plugin tablesorter and I can't call trigger twice. For example this won't work: ``` this._$table.trigger('update'); this._$table.trigger('sorton', [[[1,1]]]); ``` But this works: ``` this._$table.trigger('update'); setTimeout($.proxy(function() { this._$table.trigger('sorton', [[[1,1]]]); }, this), 1); ``` And then I see that problem was in trigger 'update', it call method with body: ``` function () { var me = this; setTimeout(function () { // rebuild parsers. me.config.parsers = buildParserCache( me, $headers); // rebuild the cache map cache = buildCache(me); }, 1); } ``` Why did the tablesorter developer use `setTimeout` with one millisecond?