typed-objects-explainer icon indicating copy to clipboard operation
typed-objects-explainer copied to clipboard

typeof on a value type

Open nikomatsakis opened this issue 9 years ago • 2 comments

Should probably yield symbol.toString() where symbol is the defining symbol. This is because @tschneidereit thinks that returning a non-string will break the web.

nikomatsakis avatar Nov 25 '15 17:11 nikomatsakis

Unless I've misunderstood this (definitely possible), this seems like a bad idea because presumably it will allow users to spoof typeof checks and causes obvious problems when different libraries create incompatible types with the same names. Avoiding this stuff is the whole point of using Symbols anyway, right?

Personally I think typeof thing === 'value' is safer. Users will presumably still be able to use instanceof if they need to differentiate?

phpnode avatar Dec 07 '15 13:12 phpnode

Yes, perhaps that is true. I was aware of possibility of spoofing but didn't consider "typeof" to be a "security" measure, but perhaps that is incorrect. Or at least, people will attempt to use it as such.

My main objection to "value" is that it means users cannot emulate the builtin types, which remain "special", but maybe that's ok.

nikomatsakis avatar Dec 14 '15 21:12 nikomatsakis