Allen Wirfs-Brock (2014-02-08T19:07:29.000Z)
On Feb 8, 2014, at 10:47 AM, Bradley Meck wrote:

> Are we able to ensure that Promises can be sub-typed right now? Did not see things in the spec about this.
> 
> In Chome/V8:
> 
> function MyPromiseType() {
>   var self=this;
>   Promise.call(this, function (f,r) {
>     self.f = f;
>     self.r = r;
>   });
> }
> MyPromiseType.prototype = Object.create(Promise.prototype);
> new MyPromiseType()
> TypeError: Failed to construct 'Promise': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
> 
> And if we do sub-type a promise, that seems to be the only way to hook into state propagation for promises (according to A+).  This means that anything wishing to have state propagation must have Promise in the prototype chain. This seems fine to me, but means modifying existing prototype chains must start from the beginning of the chain rather than being able to add a Promise interface on top of the end of the chain.
> 
> For example with the prototype chain:
> 
> Game -> CardGame -> BlackJackGame
> 

> We could not turn the BlackJack type into a promise correct? Just trying to understand at this point.

Don't know about the current V8 inpl, but this should work per the ES6 spec: 

class MyPromiseType extends Promise {
   constructor() {
       super((f,t) => this.f=f,  this.t=t)
   }
}

let my = new MyPromise;

The magic is in the Promise[Symbol.create] method which is inherited by MyPromise and invoked during (new MyPromise).  Playing around with the instance side prototype chain enough enough. 

Allen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140208/4fc3024c/attachment.html>
domenic at domenicdenicola.com (2014-02-17T21:18:29.600Z)
Don't know about the current V8 inpl, but this should work per the ES6 spec: 

```js
class MyPromiseType extends Promise {
   constructor() {
       super((f,t) => this.f=f,  this.t=t)
   }
}

let my = new MyPromise;
```

The magic is in the `Promise[Symbol.create]` method which is inherited by `MyPromise` and invoked during `(new MyPromise)`.  Playing around with the instance side prototype chain enough enough.