Friday 14 April 2017

Custom printing from console.log?

Let's say I have this class.

class Attribute {
  constructor(name) {
    this.name = name;
  }
}

And I create an instance and log it to the console for debugging purposes.

const test = new Attribute('Large');
console.log(test);

How can I get it to output a specially formatted string, like {Attribute} Large? I'm primarily concerned with Chrome support, but Node and other browsers would be nice, too.



via BlueJ774

No comments:

Post a Comment