Saturday 15 January 2011

javascript - How to get the code in promise object success function to execute before the code after that call? -



javascript - How to get the code in promise object success function to execute before the code after that call? -

i have function named handlewidgetdrop . in function phone call function insertblankwidget executes function on homecoming of promise object . problem code in handlewidgetdrop after function phone call insertblankwidget getting executed before code in promise object. how undo , execute code in function after promise object success execute before code after phone call insertblankwidget(). class="snippet-code-html lang-html prettyprint-override">handlewidgetdrop:function (){ //some lines this.insertblankwidget(); //lines after insertblankwidget phone call } insertblankwidget:function(){ var promise=this.getwidgetmodel(); promise.done(function(){ //code must executed before lines after insertblankwidget }); }

just chain .done function on promise. though, you'll have homecoming promise insertblankwidget :

insertblankwidget:function(){ var promise=this.getwidgetmodel(); promise.done(function(){ //code must executed before lines after insertblankwidget }); homecoming promise; }

then able chain in handlewidgetdrop:

handlewidgetdrop:function (){ //some lines this.insertblankwidget().done(function(){ //lines after insertblankwidget phone call }); }

javascript jquery promise

No comments:

Post a Comment