google chrome - Is there a method I can override on a JavaScript object to control what is displayed by console.log? -


I'm thinking about Chrome specifically, though firebug would be interesting. I have tried string () and valueOf (), but none of them is being used. The interesting thing is that if I take a function, this function will display the definition - but if I add string () method I'll see this zero!

  var a = function () {}; Console.log (a); // Output: function () {} a.toString = function () {return 'a'; }; Console.log (a); // output: tap a.valueOf = function () {returns 'V'; }; Console.log (a); // Output: blank  

Any ideas?

Nobody knows the way I know your best bet on that object to a toString () will be to define the method that you want to log on and then it is said directly or indirectly:

  var o = {}; O.toString = function () {back "three blind rats"; }; Console.log ("" + o); Console.log (o.toString ());  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -