Promise() vs. new Promise()

Brendan Eich brendan at mozilla.org
Wed Aug 20 13:11:21 PDT 2014


Alex Kocharin wrote:
> 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.

Gotcha, and my point was not to mandate `new`, just allow it. I thought 
we relaxed things so `new` was optional if there was no issue leaving it 
out:

http://esdiscuss.org/topic/make-class-constructors-work-with-call-too

But that was a while ago.

> 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.

Agreed, mandating `new` where there's no issue (legacy, e.g., Date; or 
other?) would be Bad(tm).

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

Hrm.

/be


More information about the es-discuss mailing list