toSource equivalent

2,589 views
Skip to first unread message

Peng Yu

unread,
Jan 9, 2012, 10:45:31 AM1/9/12
to Google Chrome Developer Tools
Hi,

I see that there is toSource in Firefox. I'm wondering if there is
anything equivalent in devtools that can print the source code of an
object. Thanks!

http://spacebug.com/javascript-object-to-string/

--
Regards,
Peng

Sam Dutton

unread,
Jan 9, 2012, 11:55:48 AM1/9/12
to Peng Yu, Google Chrome Developer Tools
Hi Peng

I'm not sure if this answers your question, but the best way to the view the details for an object in the Chrome Dev Tools is to enter its name in the console and press return!

You might also want to look at JSON.stringify().

Sam

Peng Yu

unread,
Jan 9, 2012, 12:25:52 PM1/9/12
to Sam Dutton, Google Chrome Developer Tools
> You might also want to look at JSON.stringify().

Hi Sam,

Some people mentioned this https://github.com/douglascrockford/JSON-js

But I guess, chrome already has JSON.stringify() implement. Sourcing
the above script is unnecessary and will cause problem? The following
code does not print the JSON string. I guess this is because of this
conflict?

<html>
<body>
<script type="text/javascript"
src="http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js"><script/>
<script>
var obj={x:1, y:2};
var json_data = JSON.stringify(obj);
document.write('xx' + json_data + '<br/>');
</script>
</body>
</html>


--
Regards,
Peng

PhistucK

unread,
Jan 9, 2012, 2:23:10 PM1/9/12
to Peng Yu, Sam Dutton, Google Chrome Developer Tools
json2.js is unnecessary, but even when included, it only adds JSON (and .stringify, .parse, .toJSON) when they are not natively supported. If it is supported, the script does practically nothing.

When I take your code and paste it within the Developer Tools, in its console (of the New Tab page, just for example), the page shows -
xx{"x":1,"y":2}

So I guess this is working fine. Try alert or console.log instead of document.write, perhaps.

PhistucK

tcaud...@gmail.com

unread,
Feb 19, 2012, 9:16:58 AM2/19/12
to google-chrome-...@googlegroups.com
This is why Chrome isn't my preferred browser. How hard could it be to expose the internal object copy function, like Mozilla did? Someone is missing a few screws at Google, me thinks.

tcaud...@gmail.com

unread,
Feb 19, 2012, 9:18:45 AM2/19/12
to google-chrome-...@googlegroups.com
Instead I have to rely on slow jQuery, which doesn't use internal functions but insists on doing everything the interpreted way.

pfeldman

unread,
Feb 19, 2012, 9:38:13 AM2/19/12
to Google Chrome Developer Tools
What is your scenario? Do you need toSource for debugging only? Is it
important that it conforms to the Mozilla's format? Is it important
that the references are supported?

polkovn...@gmail.com

unread,
Jan 25, 2014, 9:02:08 PM1/25/14
to google-chrome-...@googlegroups.com
I would like to add DevTools-like treeview of object properties and methods on a web page. User is entering some script, which is interpreted. It's even possible that it generates functions. I certainly need something like toSource from Firefox. I've already downloaded the DevTools section of Blink, but there're a lot of sources, and it's hard to make myself run that "inspector inception" thing without certainity that it doesn't depend on extention-only API.

понедельник, 9 января 2012 г., 17:45:31 UTC+2 пользователь Peng Yu написал:

Pavel Feldman

unread,
Jan 28, 2014, 10:32:37 AM1/28/14
to Google Chrome Developer Tools
On Sun, Jan 26, 2014 at 6:02 AM, <polkovn...@gmail.com> wrote:
I would like to add DevTools-like treeview of object properties and methods on a web page. User is entering some script, which is interpreted. It's even possible that it generates functions. I certainly need something like toSource from Firefox. I've already downloaded the DevTools section of Blink, but there're a lot of sources, and it's hard to make myself run that "inspector inception" thing without certainity that it doesn't depend on extention-only API.

I am not sure I am following your request, but if you think this could be put in form of a feature request, please file it at http://crbug.com!

Regards
Pavel
 

понедельник, 9 января 2012 г., 17:45:31 UTC+2 пользователь Peng Yu написал:
Hi,

I see that there is toSource in Firefox. I'm wondering if there is
anything equivalent in devtools that can print the source code of an
object. Thanks!

http://spacebug.com/javascript-object-to-string/

--
Regards,
Peng

--
You received this message because you are subscribed to the Google Groups "Google Chrome Developer Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-develo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-chrome-developer-tools/a65c0a6d-e1eb-4723-9e8f-664f0b4b06c4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages