json - How to modify the output in chrome console when printing a javascript object -


What would I like to know behind the scenes when printing an object in the console (like in the picture in the picture). How can I define a particular function within the object to print my own code instead of all the properties of an object (the equivalent of the string in the Objective-C)? For example, if I evaluate a in the console, then I just want to print the "Hello" string and all {one: 1, two: 2, hello: "hello"} . Can I do without using console.log () or similar functions? Enter image details here

Well, I'm not sure this is your question, but you can always override the string () method of the object.

  var a = {a: "something", hello: "hello", toString: function () {console.log (this.hello)}}; A.toString () // Prints Hello  

Hope that helps!


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? -