Proposal: allow primitives to be explicitly returned from constructors

Oriol _ oriol-bugzilla at hotmail.com
Fri Apr 20 13:23:15 UTC 2018


> You already can't assume the result is `typeof new function () { return value } === "object"`

Yes, that's why I need reliable ways to test whether a value is an object, and your proposal breaks one of these.

> here's what I usually do:
>
> ```
> function isObject(value) {
>     return value != null && (
>         typeof value === "object" ||
>         typeof value === "function"
>     )
> }

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.

-- Oriol



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180420/e9595c1e/attachment.html>


More information about the es-discuss mailing list