JavaScript native Promise() without callback

前端 未结 2 1506
轻奢々
轻奢々 2020-12-11 21:16

Look at this jQuery code:

var promise = new Deferred(),
    some;

some = function(promise) {
    // do cool things

    promise.resolve();
};

promise.then(         


        
2条回答
  •  时光说笑
    2020-12-11 22:03

    The execution flow would be a little different, but basically work the same way:

    function some(resolve, reject) {
        resolve();
    }
    
    var promise = new Promise(some);
    
    promise.then(/*  callback cool things   */);
    

    Instead of some getting passed the promise itself, it gets passed the resolve and reject functions. So, the dependency is just the other way round.

提交回复
热议问题