Re: Promise sub-class: super((resolve, reject) = this) ?

2015-06-03 Thread Allen Wirfs-Brock
On Jun 2, 2015, at 8:08 PM, Logan Smyth wrote: To clarify things, since I don't think it's been made abundantly clear, the example that Sebastian gave would work in a standard ES6 environment, correct? It is only if the callback were executed synchronously that the exception would be

Re: Promise sub-class: super((resolve, reject) = this) ?

2015-06-03 Thread Benjamin Gruenaum
Am I missing something obvious in `super((resolve, reject) = this)` ? First of all, it makes perfect sense for `this` not work work before super has been called - and it has not been called yet. I think that the crux is that the promise constructor runs _synchronously_ so when you pass it `this`

Re: Promise sub-class: super((resolve, reject) = this) ?

2015-06-03 Thread John Barton
On Wed, Jun 3, 2015 at 1:27 AM, Benjamin Gruenaum benjami...@gmail.com wrote: Am I missing something obvious in `super((resolve, reject) = this)` ? First of all, it makes perfect sense for `this` not work work before super has been called - and it has not been called yet. Rather than

Re: Promise sub-class: super((resolve, reject) = this) ?

2015-06-03 Thread Matthew Robb
It seems like, at least in the case with Promise, it could be solved also by having the this binding of the executor bound to the promise or have the promise object passed into the executor as a third argument maybe? On Jun 2, 2015 10:38 PM, Brendan Eich bren...@mozilla.org wrote: With best

Re: Promise sub-class: super((resolve, reject) = this) ?

2015-06-02 Thread Sebastian McKenzie
This is a limitation of Babel and not at all a reflection of the actual specification. This restriction is imposed order to follow ES2015 semantics of not being able to reference `this` before `super()`. It does a pretty dumb check of only allowing it to be strictly after the call (ie. not

RE: Promise sub-class: super((resolve, reject) = this) ?

2015-06-02 Thread Domenic Denicola
Hmm I am pretty sure Babel et al. are correct here in not allowing this. The super call needs to *finish* before you can use `this`. Chrome also works this way. The correct workaround is ```js let resolve, reject; super((a, b) = { resolve = a; reject = b; }); // use this ```

RE: Promise sub-class: super((resolve, reject) = this) ?

2015-06-02 Thread Sebastian McKenzie
Ah, completely right. At first glance I thought it was this similar but separate issue: ```js class Foo {   constructor(callback) {     this.callback = callback; // just storing it!   } } class Bar extends Foo {   constructor() {     super(() = this); // reference to `this` will

Re: Promise sub-class: super((resolve, reject) = this) ?

2015-06-02 Thread Matthew Robb
If I thought I could make any money then I would most definitely bet that the changes made to classes that are at the root of this problem will be the undoing of es classes and I find myself feeling more and more like avoiding them is the easiest thing to do. This use-case is a perfect example of

Re: Promise sub-class: super((resolve, reject) = this) ?

2015-06-02 Thread Logan Smyth
To clarify things, since I don't think it's been made abundantly clear, the example that Sebastian gave would work in a standard ES6 environment, correct? It is only if the callback were executed synchronously that the exception would be thrown since the `this` binding has not yet been

Re: Promise sub-class: super((resolve, reject) = this) ?

2015-06-02 Thread Kevin Smith
Hi Logan - that's correct. On Tue, Jun 2, 2015 at 11:08 PM Logan Smyth loganfsm...@gmail.com wrote: To clarify things, since I don't think it's been made abundantly clear, the example that Sebastian gave would work in a standard ES6 environment, correct? It is only if the callback were

Re: Promise sub-class: super((resolve, reject) = this) ?

2015-06-02 Thread Brendan Eich
With best intentions I must say that you are overreacting. The subject-line code (h/t Mark Miller for pointing me at it!) in context of the superclass constructor uses `this` before `super` has returned. That's a no-no for pretty-good reason. If you have a better alternative design, we needed