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

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -