What good is the reliability of something that is more often than not
useless?

Should there be a typeof hook like Symbol.hasInstance? No. `instanceof` was
always sketchy due to the ability to exchange prototypes on an object. When
`class` came along, it became effectively broken since `class` provides no
facility for transfixing the prototype attached to an instance.

On the other hand, `typeof` never had such issues. Unfortunately, when
`class` came along, nothing was done to allow `typeof` to treat classes as
unique types. That was disappointing. However, adding a hook means that
`typeof` would lose its stability and predictability, making it essentially
as useless as `instanceof`. If instead, the two changes I just mentioned
were made, then `typeof` would even be able to supplant `instanceof`
without losing any of its reliability. Just a thought...

On Sat, Jul 27, 2019 at 3:57 PM Jordan Harband <[email protected]> wrote:

> With something that while unintuitive in one case, is eternally robust and
> reliable.
>
> If you want extensibility, define Symbol.toStringTag on your objects.
>
> On Sat, Jul 27, 2019 at 1:23 PM Michael Haufe <[email protected]>
> wrote:
>
>> If it's unfixably broken[1], non-extensible, excessively vague, and
>> non-orthogonal, where does that leave you?
>>
>>
>>
>> [1] <https://twitter.com/BrendanEich/status/798317702775324672>
>>
>>
>>
>> *From:* Jordan Harband <[email protected]>
>> *Sent:* Saturday, July 27, 2019 3:00 PM
>> *To:* Michael Haufe <[email protected]>
>> *Cc:* ViliusCreator <[email protected]>; [email protected]
>> *Subject:* Re: Proposal: Typeof Trap
>>
>>
>>
>> Those two PRs are about removing implementation-defined behavior from
>> `typeof`, making it *more* reliable - there is no trend away from using and
>> relying on `typeof`, full stop.
>>
>>
>>
>> `Symbol.hasInstance` is a part of why `instanceof` is actually unreliable
>> - because user code can hook into it. It would be a massive loss imo if
>> `typeof` lost its bulletproof status by adding a user hook.
>>
>>
>>
>> On Sat, Jul 27, 2019 at 12:37 PM Michael Haufe <[email protected]>
>> wrote:
>>
>> The trend seems to be to rely on typeof less and less as time passes:
>>
>>
>>
>> From the  March 2019 Agenda <
>> https://github.com/tc39/agendas/blob/274e49412c09f81a0a82f386e6eead481c69adad/2019/03.md
>> >:
>>
>>
>>
>> “Implementation-defined typeof still necessary?” <
>> https://github.com/tc39/ecma262/issues/1440>
>>
>> “Normative: Remove implementation-defined typeof behavior” <
>> https://github.com/tc39/ecma262/pull/1441>
>>
>>
>>
>>
>>
>> The only real discussion around this I can find is from a related
>> proposal from Brendan Eich a few years ago:
>>
>>
>>
>>
>> https://esdiscuss.org/topic/typeof-extensibility-building-on-my-value-objects-slides-from-thursday-s-tc39-meeting
>>
>>
>>
>>
>>
>>
>>
>> *From:* ViliusCreator <[email protected]>
>> *Sent:* Saturday, July 27, 2019 2:04 PM
>> *To:* Michael Haufe <[email protected]>
>> *Subject:* RE: Proposal: Typeof Trap
>>
>>
>>
>> *Yes, but it traps `typeof `, not `instanceof`. There’s difference there.*
>>
>> _______________________________________________
>> es-discuss mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to