Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
439 views
in Technique[技术] by (71.8m points)

php - 在Javascript中是否存在var_dump(PHP)的等价物?(Is there an equivalent for var_dump (PHP) in Javascript?)

我们需要查看对象在Javascript中有哪些方法/字段。

  ask by eddy147 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As the others said, you can use Firebug, and that will sort you out no worries on Firefox.

(正如其他人所说,你可以使用Firebug,这样就不用担心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.

(Chrome和Safari都有一个内置的开发者控制台,它与Firebug的控制台具有几乎相同的界面,因此您的代码应该可以在这些浏览器中移植。)

For other browsers, there's Firebug Lite .

(对于其他浏览器,有Firebug Lite 。)

If Firebug isn't an option for you, then try this simple script:

(如果Firebug不适合你,那么试试这个简单的脚本:)

function dump(obj) {
    var out = '';
    for (var i in obj) {
        out += i + ": " + obj[i] + "
";
    }

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

(我建议不要警告每个属性:一些对象有很多属性,你会在那里整天点击“确定”,“确定”,“确定”,“我......该死的那个属性我是寻找”。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...