On Sat, Jan 12, 2019 at 8:19 AM Randy Buchholz <w...@randybuchholz.com> wrote:
> (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. > > > can't you just use the constructor name when needing more detail? var a = new Date(); a.constructor.name "Date" > (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 > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss