Does it expect to receive votive-like objects?

According to Mozilla , only Promises expects a wait:

[rv] Returns the allowed value of a promise, or the value itself if it is not a promise.

If you expect an immediate promise, the promise will be returned immediately and it will not wait. However, the following code expects without using Promises in Chrome and FF.

var obj = {
    then:func => obj.func=func
};
setTimeout(() => obj.func(57), 1000);

async function go() {
    var res = await obj;
    console.log(res); //shows '57' after 1000ms
}

go();

According to the specifications, are promising objects that are not Promises awaiting expectations? (I tried to look at the specifications (related to the Mozilla article), but I couldn't figure it out.)

+4
source share
2 answers

await obj.then() . obj Promise, .

.

, :

  • obj
  • setTimeout(),
  • go()
  • go()
  • await go(), obj.then(), obj.func
  • , .

  • setTimeout(), obj.func() 57

  • go(), 57
+1

:

Promise, Promise .

, Promise, .

0

Source: https://habr.com/ru/post/1681690/


All Articles