Javascript / Chrome - 如何从webkit检查器复制对象作为代码 [英] Javascript / Chrome - How to copy an object from the webkit inspector as code

查看:139
本文介绍了Javascript / Chrome - 如何从webkit检查器复制对象作为代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的javascript中做了一个console.log语句,以便记录一个javascript对象。我想知道是否有办法,一旦完成 - 将该对象作为JavaScript代码复制。我想要做的是将一个使用ajax创建的对象转换为静态JavaScript对象,以便在没有服务器的情况下可以在本地运行文件。我在铬检查器窗口中包含了该对象的屏幕截图,以便您可以看到我正在尝试执行的操作。存储为全局变量。它会返回类似于 temp1 的变量名称。 Chrome还有一个 copy()方法,因此控制台中的 copy(temp1)应该将该对象复制到剪贴板。




关于递归对象的注意事项:如果您试图复制递归对象,您将获得 [object Object] 。这是可以预料的。


I am doing a console.log statement in my javascript in order to log a javascript object. I'm wondering if there's a way, once that's done - to copy that object as javascript code. What I'm trying to do is convert an object that was created using ajax to parse an xml feed into a static javascript object so that a file can run locally, without a server. I've included a screenshot of the object in the chrome inspector window so you can see what I'm trying to do.

解决方案

  1. Right-click an object in Chrome's console and select Store as Global Variable from the context menu. It will return something like temp1 as the variable name.

  2. Chrome also has a copy() method, so copy(temp1) in the console should copy that object to your clipboard.

Note on Recursive Objects: If you're trying to copy a recursive object, you will get [object Object]. This is to be expected.

这篇关于Javascript / Chrome - 如何从webkit检查器复制对象作为代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆