我該如何解決這個問題才能打印this should show
?我正在構建一個應用程序,我需要obj: myObj
甚至obj: 'myObj'
來引用它自己。對象在JavaScript中如何引用自身?
第1-3行僅用於顯示錯誤。
let myObj = {
text: 'this shouldn\'t show'
};
myObj = {
text: 'this should show',
obj: myObj
}
function show(object) {
document.write(object.text);
}
show(myObj.obj);
'myObj.obj = MyObj中;'? – Ryan
您正在用一個新對象覆蓋'myObj',並引用舊對象。 'let myObj = {text:'this should show'}; myObj.obj = myObj;' – Thomas