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

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

javascript - Angular2 intelliJ config error.. Cannot find module '@angular/core' -