Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7750317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:15:33+00:00 2026-06-01T11:15:33+00:00

Is it possible to define an object within another object? I’m thinking something like

  • 0

Is it possible to define an object within another object? I’m thinking something like this:

function MyObj(name) {
    this.name = name;

    function EmbeddedObj(id) {
        this.id = id;
    }
}

And I could then create an EmbeddedObj like this:

var myEmbeddedObj = new MyObj.EmbeddedObj();

Meme for bonus points: Objectception! 😮

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:15:35+00:00Added an answer on June 1, 2026 at 11:15 am

    Yes, and no.

    function MyObj(name) {
        this.name = name;
    }
    MyObj.EmbeddedObj = function EmbeddedObj(id) {
        this.id = id;
    }
    new MyObj.EmbeddedObj(42);
    

    Would run, but it might not yield the expected results for “embedded object” (see comment).

    Note that in the case of new expr the expression is evaluated first so, in this case it creates a new object using the function-object evaluated from MyObject.EmbeddedObj as a constructor. (There is a silly rule with parenthesis in the expression, but that’s another story.)


    Now, if a “parent” and “child” relationship was desired, that could be done, using a more round-about method:

    function Parent (name) {
       this.name = name;
       var parent = this; // for closure
       this.Child = function Child () {
          this.Parent = parent;
       }
    }
    
    // create new parent object
    var parent = new Parent();       
    // each new parent has a different Child constructor and
    // any function-object can be used as a constructor
    var child = new parent.Child();
    // true: child is "bound" to parent
    child.Parent === parent;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to execute a proc within the context of another object? I
Possible Duplicate: ASP.NET MVC: No parameterless constructor defined for this object I'm working on
Is it possible to define a spring-managed EJB3 hibernate listener? I have this definition
Is it possible to define a event handler of one type of HTML object
Is it possible to use an object within an object? For example, I have
In Zend Framework, is it possible to add functionality to the $this object used
When serializing based on a Java object, is it possible to define a schemaLocation
Possible Duplicates: Why does this go into an infinite loop? Things like i =
For instance, is the following possible: #define definer(x) #define #x?
Possible Duplicate: Define a method that has many (or infinite) arguments I have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.