Open brettz9 opened 6 years ago
"Builtin" isn't a great name here. The proposal already allows an object to define its own custom Symbol.builtin
function, which allows the use case you're referring to.
Sure that works if a class defines it--but what about constructors beyond one's control?
Then you're constrained to the API that code beyond your control provides you :-) having a fallback to Object.prototype.toString.call
is something you can easily build in an abstraction.
Even the short form, {}.toString.call(val).slice(8, -1)
, is an ugly mess of implementation-leaking. If not integrated with this type-checking, I think it deserves its own API.
While this flies in the face of the name referring to
Builtin
, I'd think it would be useful, as well as semantically pleasing to have another method to return the same values as in your proposal but returning{}.toString.call(val).slice(8, -1)
withSymbol.toStringTag
for constructed user objects.One could thus benefit from:
While this may be technically out of scope for your proposal, I'd think it might be considered together if it is deemed worthwhile.