(Hi all, new to group)
Some of the Well Known Symbols are linked to standard functions -
Symbol.toStringTag - A string value used for the default description of an
object. Used by Object.prototype.toString().
When I have a Class instance (say, `const flow = new Flow()`, the debugger
shows `flow = Flow {`.
But when I do `console.log( typeof flow)` the output is `object`.
I assume changing basic behavior `typeof` would be breaking, but extending it
through a symbol would be useful.
`Symbol.typeofTag` of just `Symbol.typeof`
Invoking `typeof` on an object with this symbol would return "user-typed"
information.
(Posting Question)
What is the preferred format/approach for highlighting code in posts?
____________________
Possible Approaches
```
class Flow {
get [Symbol.typeof]() { return Flow; } or { return "Flow" }
}
```
would work much like Symbol.species. Implicitly casting to string would be
more intuitive I think.
Other approaches, (special handling of well-knowns) could be:
Decorator-ish
```
[Symbol.typeof] = "Flow"
Class Flow {...
```
or inferred
```
[Symbol.typeof]
class Flow {...
```
Internal - In class, but not in a function.
```
Class Flow {
[Symbol.typeof]
or
[Symbol.typeof] = "Flow"
or
[Symbol.typeof] = Flow
or
[Symbol.typeof] = this
```
Constructor
```
Class Flow {
Constructor() {
this[Symbol.typeof] = ...
...
```
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss