Javascript / Chrome - 如何从webkit检查器复制对象作为代码 [英] Javascript / Chrome - How to copy an object from the webkit inspector as code
问题描述
我在我的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.
Right-click an object in Chrome's console and select
Store as Global Variable
from the context menu. It will return something liketemp1
as the variable name.Chrome also has a
copy()
method, socopy(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屋!