Promise.resolve vs resolve

后端 未结 2 862
傲寒
傲寒 2021-01-22 07:11

I have this code:

var promise1 = new Promise(function(resolve, reject) {
  setTimeout(() => {
         console.warn(\'Elo\');
         resolve(\'First response         


        
2条回答
  •  深忆病人
    2021-01-22 07:52

    The new Promise constructor passes a specific function into your callback, which becomes your resolve parameter. That promise (the one you're constructing there with new Promise) can only be resolved by calling that specific resolve function.

    Promise.resolve simply creates a new "pre-resolved" promise. It does not resolve any existing promise (nor would it have any way of knowing which promise it's supposed to resolve).

提交回复
热议问题