请分享有关下方输出你的看法。记录JavaScript对象的属性
var a = '';
console.log(a); //this logs nothing as expected.
a = 'triven';
var a = {};
console.log(a); // How javascript is aware of property here that is defined below.
a.name = 'triven';
请分享有关下方输出你的看法。记录JavaScript对象的属性
var a = '';
console.log(a); //this logs nothing as expected.
a = 'triven';
var a = {};
console.log(a); // How javascript is aware of property here that is defined below.
a.name = 'triven';
我认为你正在寻找console.dir()
。
console.log()
不会做你想做的,因为它打印到对象的引用,并通过你的流行打开的时候,它的改变。 console.dir
在您调用对象时打印对象中的属性目录。下面
的JSON的想法是好的;你甚至可以去解析JSON字符串,并获得可浏览的对象喜欢什么.DIR()会给你:
console.log(JSON.parse(JSON.stringify(obj)));
将鼠标放在“我” – Ryan
什么让你烦恼? –