On 9/15/17 9:58 AM, David Bruant wrote:
Maybe @@toStringTag will end up not working well enough for your need anyway.
Not least because its use is kinda ugly, no?
But another solution could be to define a chromeonly symbol for the brand.
obj[Symbol.brand] === 'HTMLEmbedElement'
(`Symbol.brand` is chromeonly. `obj[Symbol.brand]` too)
That doesn't solve the problem of detecting whether 'obj' is an
HTMLElement, does it?
You could have obj[Symbol.brand] be an array of all the relevant brands,
and do:
obj[Symbol.brand].includes('HTMLEmbedElement')
but now we're getting into pretty ugly and rather non-obvious territory.
(There's also a slight concern about practicality here, because we do
not want to define a brand property on every single object for
performance and memory reasons, but that can probably be addressed by
having an accessor property for Symbol.brand on the proto that checks
the 'this' value to decide what to return... Even then, I expect that
this solution is much slower than the other ones proposed here, because
it relies on property access across Xrays, whereas the other things that
were proposed do not.)
No function call, no string to allocate, nothing to import (`Symbol` is a
standard ECMAScript global).
There's a hidden function call here to call the getter. And an array
allocation for the return value, likely, or lots of machinery to try to
cache it somewhere hidden on the proto. But yes, nothing to import. ;)
-Boris
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform