It is recommended to utilize Deno.inspect(someObject)
in most cases.
If you need to customize the string representation of Deno.inspect
for a specific class, starting from Deno 1.19, you should implement something similar to the following:
class MyClass {
// …
[Symbol.for("Deno.customInspect")]() {
return "custom string representation;
}
// …
}
Any objects displayed using console.log(someObject)
will also be impacted by this customization.
You can find more information in the documentation here.
Please note that the method demonstrated by @Lukalot has been deprecated since Deno 1.19 and may not work in upcoming versions.