[英]Can I have objects inside an object in JavaScript?
So I want to have objects in objects eg 所以我想在对象中包含对象
1. var Parent={
2. var Child1 = {
3. funct:function(){
4. ...
5. },
6. funct2:function(){
7. ...
8. }
9. },
10. var Child2 = {
11. funct3:function(){
12. ...
13. }
14. }
15. }
so I can do something like Parent.Child1.funct() ...etc. 所以我可以做类似Parent.Child1.funct()...之类的事情。 Is there a way to do this? 有没有办法做到这一点?
Yes, but you'll need to respect the object syntax. 是的,但是您需要遵守对象语法。
var Parent = {
Child1: {
funct: function() {
}
},
Child2: {
funct: function() {
}
}
};
Sure, it's just another property: 当然,这只是另一个属性:
var Parent={
Child1: {
funct: function() {}
},
Child2: {
funct: function() {}
}
}
Parent.Child1.funct();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.