作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我知道 firebug 中的 console.log,这个东西叫做 dbug (但根本不是我想要的)。我正在寻找的东西可以给我一个 pretty-print 嵌套 View 到一个对象,对于 javascript 看起来像这样:
(来源:ospinto.com)
I'm also aware of this question ,并且正在寻找更表格化的内容。
最佳答案
一次尝试:
代码:
var prettyPrint = (function(){
var htmlObj = function(obj){
if (Object.prototype.toString.call(obj) === '[object RegExp]') {
return obj.toSource ? obj.toSource() : '/' + obj.source + '/';
}
if (typeof obj === 'object') {
return prettyPrint(obj);
}
if (typeof obj === 'function') {
return document.createTextNode('function(){...}');
}
return obj.toString();
},
row = function(cells, type){
type = type || 'td';
var r = document.createElement('tr');
for (var i = 0, l = cells.length; i < l; i++) {
var td = document.createElement(type);
td.appendChild(typeof cells[i] === 'string' ? document.createTextNode(cells[i]) : cells[i]);
r.appendChild(td);
}
return r;
},
heading = function() {
var thead = document.createElement('thead');
thead.appendChild(row(['Name','Value'], 'th'));
return thead;
};
return function(obj) {
var tbl = document.createElement('table'),
tbody = document.createElement('tbody');
for (var i in obj) {
var objCellContent = obj[i] === obj ? document.createTextNode('CIRCULAR REFERENCE') : htmlObj(obj[i]);
tbody.appendChild( row([document.createTextNode(i), objCellContent]) );
}
tbl.appendChild(heading());
tbl.appendChild(tbody);
return tbl;
};
})();
关于javascript - 是否有任何等效于 javascript 的 dbug(*真正*漂亮的 vars 打印)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/946984/
在 Jetty (7.1.5) 中运行 CometD Bayeux 实现时,大量 DBUG 级别的日志记录会输出到控制台。我已将记录器识别为 org.eclipse.jetty.util.log.St
我知道 firebug 中的 console.log,这个东西叫做 dbug (但根本不是我想要的)。我正在寻找的东西可以给我一个 pretty-print 嵌套 View 到一个对象,对于 java
我是一名优秀的程序员,十分优秀!