javascript - why 'setTimeout' in 'bsTransitionend'? -
i going through code of carasoul.js , came across following line of code ::
settimeout(function () { that.$element.trigger(slidevent) }, 0)
well simple above line of code doing , below line of code ::
that.$element.trigger(slidevent)
is executed @ interval of 0 , question , context of piece of code , if author wanted run function/execute line of code , have done without settimeout , in case ,
instead of ::
settimeout(function () { that.$element.trigger(slidevent) }, 0)
the author have written following lines of code ::
that.$element.trigger(slidevent)
so why set time out , context ??
below entire snippet of code , makes more sense ::
$active .one('bstransitionend', function () { $next.removeclass([type, direction].join(' ')).addclass('active') $active.removeclass(['active', direction].join(' ')) that.sliding = false settimeout(function () { that.$element.trigger(slidevent) }, 0) })
the entire code can found on git here. (line 156).
to repeat question , why settimeout used when seems doing nothing ?
this done call function on next cycle. use when need wait dom refresh or other event dispatch in cycle.
you're adding function in settimeout queue , in next cycle when settimeout queue checked method executed because time (0) passed.
possible duplicate: why settimeout(fn, 0) useful?
Comments
Post a Comment