javascript - Custom printing from console.log? -
let's have class.
class attribute { constructor(name) { this.name = name; } } and create instance , log console debugging purposes.
const test = new attribute('large'); console.log(test); how can output specially formatted string, {attribute} large? i'm concerned chrome support, node , other browsers nice, too.
class attribute { constructor(name) { this.name = name; } tostring(){//simply set string method? return "{attribute} "+this.name; } } as console.log not call string either do:
const test = new attribute('large'); console.log(test+""); or create own logging function
Comments
Post a Comment