請分享有關下方輸出你的看法。記錄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
什麼讓你煩惱? –