在Javascript中是否存在var_dump(PHP)的等价物? [英] Is there an equivalent for var_dump (PHP) in Javascript?
问题描述
我们需要查看对象在Javascript中有哪些方法/字段。
We need to see what methods/fields an object has in Javascript.
推荐答案
正如其他人所说,你可以使用Firebug,这将让你不用担心Firefox。 Chrome& Safari都有一个内置的开发人员控制台,它与Firebug的控制台具有几乎相同的界面,因此您的代码应该可以在这些浏览器中移植。对于其他浏览器,有 Firebug Lite 。
As the others said, you can use Firebug, and that will sort you out no worries on Firefox. Chrome & Safari both have a built-in developer console which has an almost identical interface to Firebug's console, so your code should be portable across those browsers. For other browsers, there's Firebug Lite.
如果Firebug不是你的选择,那么试试这个简单的脚本:
If Firebug isn't an option for you, then try this simple script:
function dump(obj) {
var out = '';
for (var i in obj) {
out += i + ": " + obj[i] + "\n";
}
alert(out);
// or, if you wanted to avoid alerts...
var pre = document.createElement('pre');
pre.innerHTML = out;
document.body.appendChild(pre)
}
我建议反对警告每个人的财产:一些物品有很多属性,你会在那里整天点击确定,确定,确定,我......该死的那是我正在寻找的财产。
I'd recommend against alerting each individual property: some objects have a LOT of properties and you'll be there all day clicking "OK", "OK", "OK", "O... dammit that was the property I was looking for".
这篇关于在Javascript中是否存在var_dump(PHP)的等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!