media-type icon indicating copy to clipboard operation
media-type copied to clipboard

Rename MediaType.prototype.asString to MediaType.prototype.toString

Open moll opened this issue 11 years ago • 2 comments

JavaScript invokes toString when converting an object to a string. If you'd rename the current asString to toString, this would follow that convention.

Cheers

moll avatar Oct 15 '14 13:10 moll

Hi Andri, #2 provides the original reasoning behind the use of an explicit asString vs implicit toString.

IIRC, if Node.js' console.dir allowed the use of custom inspect methods this wouldn't be a problem.

Are you aware of a better solution?

lovell avatar Oct 15 '14 13:10 lovell

Well, I'd say API global consistency and conventions are most important and debug workarounds are second to that. In JavaScript that would be toString (and toJSON and parse, but that for another day ;-).

If console.dir stringifies an object with toString, then that its problem and should be fixed there. Skimming only the code of console.dir and util.inspect didn't seem to hint that, though.

moll avatar Oct 15 '14 21:10 moll