开发者

What's the JavaScript equivalent of Ruby's "inspect"?

In Ruby, you can do foo.inspect and it开发者_Go百科 outputs something sane for any object pretty much regardless of type.

How do I achieve the same thing in JavaScript?


JSON.stringify(foo) works pretty well.


This is possibly not the entirely general answer you're hoping for, since this introduces third-party dependencies into you application. However, they're worth mentioning:

  • For applications using Prototype (link) you can use Object.inspect (link)
  • For applications using jQuery (link) there's the jquery-inspect (link) plugin


Take a look at this:

http://jsclass.jcoglan.com/reflection.html

Did that help?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜