Is there a method I can override on a JavaScript object to control what is displayed by console.log?
Posted
by agnoster
on Stack Overflow
See other posts from Stack Overflow
or by agnoster
Published on 2010-06-02T19:27:22Z
Indexed on
2010/06/02
21:54 UTC
Read the original article
Hit count: 137
I'm thinking in particular of Chrome, though Firebug would be interesting to. I've tried toString() and valueOf(), but neither of those seem to be used. Interestingly, if I take a function it'll display the function definition - but then if I add a toString() method it will show null!
var a = function(){};
console.log(a); // output: function (){}
a.toString = function(){ return 'a'; };
console.log(a); // output: null
a.valueOf = function(){ return 'v'; };
console.log(a); // output: null
Any ideas?
© Stack Overflow or respective owner