在Javascript中是否有等效的var

编程入门 行业动态 更新时间:2024-10-26 23:27:01
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 。

如果Firebug不是您的选择,请尝试这个简单的脚本:

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) }

我建议不要警告每个单独的财产:一些对象有很多属性,你会在那里点击“确定”,“确定”,“确定”,“哦...这是我所属的财产寻找”。

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.

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".

更多推荐

本文发布于:2023-04-27 12:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327119.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Javascript   var

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!