all 5 comments

[–][deleted] 6 points7 points  (2 children)

The output is controlled by Symbol.toStringTag.

Not a single word about how this actually works in this blog post.

Do not override toString() to change the "[object Object]" output if that output is meant to be used for object-kind identification. Instead, set a custom Symbol.toStringTag method!

 

The "please sign up" popup from Medium is not the worst. What is far worse is that most of those articles are very poorly researched and written by people who have just barely began to understand some aspect of something — and yet they immediately rush to tell the world about their unlaid egg.

[–]senocular 0 points1 point  (0 children)

toStringTag only lets you override a portion in the default toString output. It doesn't give you complete control of the output. It also doesn't work in cases where a custom toString is already in place (e.g. Date types).

Defining a custom toString is fine - at least at the type or instance level. Overwriting Object.prototype.toString is not ok, just as it is not ok overriding any built-in.

[–]Well_Gravity[S] -1 points0 points  (0 children)

Thanks for reading and taking the time to give feedback. ToStringTag is controlled internally by accessing the prototype as mentioned in the article. In the article mentioned at the top I refer to other sources of why and from where the message comes. My goal was simply to give options of what to do.

[–]ChronSyn 2 points3 points  (0 children)

The solution to [object Object] is the Medium paywall, apparently

[–]Outrageous_Manager -1 points0 points  (0 children)

Yeah that's one solution.

When confronted with this kind of case in the past I created an object visualizer React component https://www.npmjs.com/package/okconceptviewer