domenic at domenicdenicola.com (2013-08-05T20:04:33.228Z)
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:
```js
Promise.register = function(C) {
C.prototype[@@isPromise] = true
}
```
But the trick with the symbol is an implementation detail.
Le 1 août 2013 à 00:53, Claude Pache <claude.pache at gmail.com> a écrit : > > > Le 31 juil. 2013 à 20:23, "Tab Atkins Jr." <jackalmage at gmail.com> 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: http://people.mozilla.org/~jorendorff/es6-draft.html > 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. —Claude -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130802/1ffe45f4/attachment-0001.html>