Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 141695

How to change Object.prototype.toString?

$
0
0

I have a class:

class Test{
    contructor(){
       this.x = "test"
    }
} 

var t = new Test()

var toString = Object.prototype.toString
console.log(toString.call(t))

the log prints [object Object], i would like it to print something like [object Test], how can i do that? I tried doing

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

but that didn't work, any help?


Viewing all articles
Browse latest Browse all 141695

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>