javascript - What comes first .always() or .then() callbacks in jQuery? -


this question has answer here:

if have function has both .then , .always callbacks, 1 executed first?

taken deferred.resolve() documentation:

when deferred resolved, donecallbacks added deferred.then() or deferred.done() called. callbacks executed in order added.

example below:

var $logger = $("#logentry");  function addlog(content){     $logger.append($("<li/>").html(content));  }    var newpromise = $.deferred();    $.when(newpromise).done(function() {      addlog("1st $when().done!");  });    newpromise.then(function() {      addlog("1st then!");  }).always(function() {      addlog("1st always!");  }).done(function() {      addlog("1st done!");  }).done(function() {      addlog("2nd done!");  }).always(function() {      addlog("2nd always!");  }).then(function() {      addlog("2nd then!");  });    $.when(newpromise).done(function() {      addlog("2nd $when().done!");  });    addlog("resolving promise!");    newpromise.resolve();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <ul id="logentry"></ul>


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -