Proposal: allow primitives to be explicitly returned from constructors
Isiah Meadows
isiahmeadows at gmail.com
Fri Apr 20 15:39:23 UTC 2018
Okay, you could invert the condition and do it this way. If it's
spec-conforming, this should work:
```js
function isObject(value) {
return value != null &&
typeof value !== "boolean" &&
typeof value !== "number" &&
typeof value !== "string" &&
typeof value !== "symbol"
}
```
Alternative, if you're okay with builtins (and this is what I
initially had before I sent the original message), you could do this:
```js
var toObject = Object
function isObject(value) {
return value === toObject(value)
}
```
-----
Isiah Meadows
me at isiahmeadows.com
Looking for web consulting? Or a new website?
Send me an email and we can get started.
www.isiahmeadows.com
On Fri, Apr 20, 2018 at 9:23 AM, Oriol _ <oriol-bugzilla at hotmail.com> wrote:
>> 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
>
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
More information about the es-discuss
mailing list