对象文字可以嵌套多远? [英] How far can an object literal be nested?
本文介绍了对象文字可以嵌套多远?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现可以将另一个属性嵌套在对象文字属性内.这是一个示例:
I have found that it is possible to nest another property within an object literal property. Here is an example of this:
var rectangle = {
upperLeft : { x : 2, y : 2 },
lowerRight : { x : 4, y : 4}
};
但是,当我尝试在该嵌套属性中嵌套另一个属性时,我无法使其正常工作.也许我的语法不正确?这是我的代码:
However, when I tried to nest yet another property within that nested property, I could not get this to work. Is maybe my syntax incorrect? Here is my code:
var rectangle = {
upperLeft : { x : {min: 2, max: 4}, y : 2 },
lowerRight : { x : {min: 4, max: 6}, y : 4}
};
推荐答案
您的第二个示例很好.当您访问时:
Your second sample is fine. When you access:
rectangle.upperLeft.x.min
它正确返回2
.您遇到什么问题?请注意,没有理论上的最大嵌套级别.
it correctly returns 2
. What problems do you encounter? Note that there is no theoretical maximum nesting level.
这篇关于对象文字可以嵌套多远?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文