typed-objects-explainer
typed-objects-explainer copied to clipboard
typeof on a value type
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.
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?
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.