Promise() vs. new Promise()

Alex Kocharin alex at kocharin.ru
Wed Aug 20 12:10:33 PDT 2014



20.08.2014, 22:47, "Brendan Eich" <brendan at mozilla.org>:
> Alex Kocharin wrote:
>>  Still doesn't make much sense... This pattern (this instanceof ...) breaks another pattern (BaseClass.call(this)). Why first one is deprecated, not the second one?
>
> Fair point, and a topic at the last TC39 meeting was to *finally* add a
> way in JS to tell whether your constructor function was called via new
> or directly.
>>  I mean, I was able to subclass such a class with prototype injection without any issues, and it feels more natural in javascript after all.
>
> You mean using `new`? Mileage varies, but I agree that client code that
> uses `new` well can add clarity about costs and reference uniqueness
> (lack of aliasing).

I mean, not using `new`. JS is a functional language after all, and having a function that can't be called as a function is weird.

If constructor supports calling it without new, I can pass it around as a function, do this for example:

```
> ['foo', 'bar'].map(Error)
[ [Error: foo], [Error: bar] ]
```

With mandatory `new` this would be much less elegant.

I was about to construct realistically-looking chain with [fn1, fn2, fn3].map(Promise).forEach(addThenHandler), but FF already seem to throw on it. :(


More information about the es-discuss mailing list