let statList = {
title: {
x: "center"
},
xAxis: {
type: "category",
axisTick: {
alignWithLabel: true
}
},
yAxis: {
type: "value"
}
};
let statObj = {};
statObj.chatObj = Object.create(statList);
statObj.carObj = Object.create(statList);
statObj.saObj = Object.create(statList);
statObj.chatObj.xAxis.data = [1, 2, 3];
statObj.carObj.xAxis.data = [4, 5, 6];
statObj.saObj.xAxis.data = [7, 8, 9];
console.log(statObj)
爲什麼返回statObj.XX.xAxis.data
一樣嗎?
爲什麼當我用console.log(JSON.stringify(statObj))
時,結果是{"chatObj":{},"carObj":{},"saObj":{}}
?
試試這個:alert((statObj.chatObj === statList));這會告訴你是否創建了statList的副本,或者實際上它只是對statList的引用,這可以解釋爲什麼它們是相同的。 – SPlatten