How does a decision of a promise decide whether to consider the return value as a promise or as a simple value?

The promise "useful" performs different actions depending on whether the return value of resolve () or the return value of the function passed to then () is a promise or not.

Therefore, understanding and predicting behavior requires knowing which criterion is used (or allowed to be used) in order to determine if something is a “promise”, because I use the phrase in the above sentence, so I would like to nail it. I'm interested in Promises / A + in general and ES6 native promises in particular.

Looking at https://promisesaplus.com/ , he says:

1.1 "promise" is an object or function with a "then" method
    whose behavior conforms to this specification.

To understand what this means, I look further in 2.2 “Then the method” and find that it relies on a set, it seems impossible to unambiguously determine whether this object is a promise or not (proof of the stopping problem). And it is beautiful; it simply means the specification of the “useful” behavior in question will not use the term “this promise” directly.

So, looking further at the specifics of the “useful” behavior, I find 2.3 “Procedure for resolving promises”. Surprise! He really uses the term "this promise" directly:

2.3.2 If x is a promise, adopt its state [3.4]

But he saves himself from descending to meaninglessness in a footnote:

[3.4] Generally, it will only be known that x is a true promise
      if it comes from the current implementation. This clause allows
      the use of implementation-specific means to adopt the state of
      known-conformant promises.
In other words, 2.3.2 did not really mean "If x is a promise," it really meant (and should say, IMO) "If x is known to be a promise."

But, if I understand correctly, this part is just a shortcut allowed for it, if it can be safe for this. Moving on, the relevant section seems to be 2.3.3, which I summarize as: consider the return value of x as a promise iff x has a property called "then", which is a function.

So, all of this is based on the definition of "x.then is a function." What does this mean, specifically for the purposes of someone who wants to implement the appropriate library, or someone wants to predict what the corresponding library should / should do when I use it? Is that the same thing to say typeof x.then === "function"?

, ( ), ES6 native promises, promises MDN. , 25.4.1.3.2. , - IsCallable (x.then); , , IsCallable , " ", " ", .

, , , : - (

" , ?", , , , , : , Promises/A +, " "?

(, , ) :

  • native promises ?
  • promises ' Promises/A + " " ?
  • , , , , ?
+4
1

, "x.then ". , , typeof x.then === "function"?

, . x.then , try.

promises ' promises/A + " " ?

spec . "function" " ", isCallable - . , typeof operator, , "function".


Btw, promises/A + Specification, "thenable" "" .

+1

All Articles