Skip to content Skip to sidebar Skip to footer

Js How To Print The Objectname To Console

When using the webdev tools console, if type a browser object, it returns console > console Console { } > console+'' '[object Console]' > console.log(console) undefined &

Solution 1:

You can override the toString() method in MyObj.prototype:

MyObj.prototype.toString = function(){ return "[object MyObj]";}

Example

var MyObj = function(){};    
MyObj.prototype.toString = function(){ return "[object MyObj]"; };

var instance = new MyObj();

console.log(instance + "");
// "[object MyObj]"

Post a Comment for "Js How To Print The Objectname To Console"