How far can an object literal be nested? [closed]

元气小坏坏 提交于 2019-12-11 11:41:57

问题


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}
};

回答1:


Your second sample is fine. When you access:

rectangle.upperLeft.x.min

it correctly returns 2. What problems do you encounter? Note that there is no theoretical maximum nesting level.



来源:https://stackoverflow.com/questions/10604995/how-far-can-an-object-literal-be-nested

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!