1

So I want to have objects in objects e.g.

 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. Is there a way to do this?

2
  • As @Guilherme Sehn said, you have to follow object's syntax. You can have pretty much anything inside an object. It's just another key/value pairs or properties. Commented Nov 30, 2013 at 20:36
  • Ohh, great! I thought it was more complicated :D Commented Nov 30, 2013 at 20:38

2 Answers 2

4

Yes, but you'll need to respect the object syntax.

var Parent = {
    Child1: {
        funct: function() {
        }
    },
    Child2: {
        funct: function() {
        }
    }
};
Sign up to request clarification or add additional context in comments.

Comments

3

Sure, it's just another property:

var Parent={
  Child1: {
    funct: function() {}
  },
  Child2: {
    funct: function() {}
  }
}

Parent.Child1.funct();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.