Reflect.type

Jordan Harband ljharb at gmail.com
Sat Jun 6 16:23:26 UTC 2015


How would your `isA` work across realms, taking a built-in constructor?
`[1,2] instanceof Array` does not, which is why `Array.isArray` exists.
`Object(42) instanceof Number` would have the same problem.

if `class SubThing extends Thing {}`, then `new SubThing instanceof Thing`
would be true.

Based on your isA examples, `Object(foo) instanceof bar` should be reliable
within a single realm, and works everywhere, without the need for a new
builtin method.

On Sat, Jun 6, 2015 at 6:32 AM, Thaddee Tyl <thaddee.tyl at gmail.com> wrote:

> You suggest a list of types of fixed size. The lack of exposition of
> user-definable value types is a problem you mention.
>
> Having a better typeof is not as useful as having a better instanceof.
>
> This would be more valuable:
>
> ```js
> isA(42, Number) === true  // Doesn't work with instanceof
> isA([1,3], Array) === true  // Does work with instanceof
> isA({one:1}, Object) === true  // The distinction between array and
> object was always weird with typeof
> class Thing {}
> isA(new Thing, Thing) === true
> class SubThing {}
> isA(new SubThing, Thing) === true  // Detects subclassing / prototype
> chain (which instanceof does not do)
> ```
>
> JS needs Ruby's is_a?.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150606/509f3ff7/attachment.html>


More information about the es-discuss mailing list