How to fetch value from Promise object after promise has been resolved

后端 未结 2 1100
难免孤独
难免孤独 2021-02-20 12:46

Please note This is a contrived example.

    function longFunc(){
        var deferred = $.Deferred();

        setTimeout(function(){
            console.log(\"         


        
2条回答
  •  梦毁少年i
    2021-02-20 13:10

    Just chain another then call, since shortAfterLongFunc returns new promise you can further work with it:

    longFunc().then(shortAfterLongFunc).then(function(data) {
        console.log('all is complted', data);
    });
    

    Demo: http://jsfiddle.net/ebt4pxxa/2/

提交回复
热议问题