Chrome的内置JavaScript控制台可以显示颜色吗?
我想要红色错误,橙色警告和console.log绿色警告.那可能吗?
我想将DOM节点甚至整个序列化为windowJSON.
例如:
>> serialize(document)
-> {
"URL": "http://stackoverflow.com/posts/2303713",
"body": {
"aLink": "",
"attributes": [
"getNamedItem": "function getNamedItem() { [native code] }",
...
],
...
"ownerDocument": "#" // recursive link here
},
...
}
Run Code Online (Sandbox Code Playgroud)
JSON.stringify(window) // TypeError: Converting circular structure to JSON
Run Code Online (Sandbox Code Playgroud)
问题是JSON默认不支持循环引用.
var obj = {}
obj.me = obj
JSON.stringify(obj) // TypeError: Converting circular structure to JSON
Run Code Online (Sandbox Code Playgroud)
window和DOM节点有很多.window === window.window将如此document.body.ownerDocument === document.
此外,JSON.stringify不序列化函数,所以这不是我想要的.
`dojox.json.ref.toJson()` can easily serialize object with …Run Code Online (Sandbox Code Playgroud) 我最接近Python的repr的是这样的:
function User(name, password){
this.name = name;
this.password = password;
}
User.prototype.toString = function(){
return this.name;
};
var user = new User('example', 'password');
console.log(user.toString()) // but user.name would be even shorter
Run Code Online (Sandbox Code Playgroud)
有没有办法在object默认情况下将字符表示为字符串?或者我将不得不object.variable用来获得我想要的结果?