这是我的代码的 jsfiddle。吨
function test(i)
{
if(i==2)
return {title:"finished at 2", data:"empty"}
else
{
a=[]
a.push(test(i+1))
a.push(test(i+1))
return {title:"number "+i, data:a}
}
}
alert(JSON.stringify(test(0)))
这里,test(0)
应该
{
title: "number 0",
data: [{
title: "number 1",
data: [{
title: "finished at 2",
data: "Empty"
}, {
title: "finished at 2",
data: "Empty"
}]
}, {
title: "number 1",
data: [{
title: "finished at 2",
data: "Empty"
}, {
title: "finished at 2",
data: "Empty"
}]
}]
虽然您可以看到它在代码结果中有所不同。如何和为什么?我该怎么做才能使它正确?