Promises Consensus

Claude Pache claude.pache at
Fri Aug 2 03:14:03 PDT 2013

Le 1 août 2013 à 00:53, Claude Pache <claude.pache at> a écrit :

> Le 31 juil. 2013 à 20:23, "Tab Atkins Jr." <jackalmage at> a écrit :
>> The first issue still up for community discussion involves the
>> definition of "promise-like".
>> We'd like the definition to be: (a) a Promise or subtype, or (b) a
>> branded non-Promise (with the branding done via Symbol or similar).
>> Promises/A+ wants the branding to be done via a method named "then"
>> (the "thenable" concept).
>> This, unfortunately, goes directly against TC39 practices in a number
>> of other areas, such as iterators, where we don't want short string
>> names as branding due to the possibility of collision.  (In the case
>> of "then", collision isn't a possibility, it's a certainty - we *know*
>> there are libraries out there today that put a "then" method on their
>> objects without referring to Promises.)  Thoughts?
> I suggest an @@isPromise builtin symbol, which works the same way as @@isRegExp in the ES6 spec [1]: An object is reputed to be a promise if and only if it has a property (either own or inherited) named @@isPromise. And `Promise.prototype` has initially an @@isPromise own property, so that instances of subclasses of `Promise` are recognised as promises.
> (With this solution, you have not to choose between subclassing or branding, but you have the both. :-) )
> —Claude
> [1] search the occurrences of @@isRegExp in:

One more idea: a `Promise.register` function, which takes a class (i.e. a constructor) `C` as argument, and whose purpose is to declare that instances of `C` are to be treated as promises.

Concretely, if the @@isPromise design is retained, that function can be implemented as following:
	Promise.register = function(C) {
		C.prototype[@@isPromise] = true
But the trick with the symbol is an implementation detail.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list