1// Yes, in node.js you can install the "util" module (nodejs api module)
2// Like this
3class MyClass {
4 constructor(text) {
5 this.text = text;
6 }
7 [util.inspect.custom]() {
8 return this.text;
9 }
10}
11const classInstance = new MyClass("Hello World!");
12console.log(classInstance); // Will log "Hello World!"
13// Keep in mind, this also affects usage in other areas, so make sure to
14// only do this when necessary. Or keep tabs on the actual class too
15class MyClass {
16 constructor(text) {
17 this.text = text;
18 this.classInstance = this; // This
19 }
20 [util.inspect.custom]() {
21 return this.text;
22 }
23}