Proposal: allow primitives to be explicitly returned from constructors
thysultan at gmail.com
Fri Apr 20 15:50:00 UTC 2018
One of the use case for this is – given a function that is either one that
returns an instance or one that returns an explicit return value, but would
otherwise throw if invoked without the "new" keyword.
Always being able to safely invoke it with "new" is a nice guarantee to
have that wouldn't require you to explicitly know before hand whether a
function is a constructor or function.
Now since this does not reflect well on the variants that return primitives
it means you cannot currently always use "new".
Broadly put this could touch on every use case thats involves the need to
know whether a function is a constructor or not before you decide to call
it with "new" or not because not calling it with "new" might throw an error.
On Fri, Apr 20, 2018 at 4:49 PM, Naveen Chawla <naveen.chwl at gmail.com>
> What's the use case? Maybe there's a nice way of doing what you want
> On Fri, 20 Apr 2018 at 19:17 T.J. Crowder <tj.crowder at farsightsoftware.com>
>> On Fri, Apr 20, 2018 at 2:23 PM, Oriol _
>> <oriol-bugzilla at hotmail.com> wrote:
>> > No, `typeof` is not reliable, because it's implementation-defined
>> > for non-standard non-callable exotic objects.
>> > For example, old IE used to return `"unknown"` in various cases.
>> Also `"object"` for host-provided functions (such as
>> `document.createElement`); IE8 still does that. (Thankfully IE11 doesn't.)
>> (I suppose that would have passed Isiah's `isObject` test anyway, but the
>> point is that `typeof` is, sadly, a weak reed...)
>> -- T.J. Crowder
>> es-discuss mailing list
>> es-discuss at mozilla.org
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss