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

  • Home
  • SEARCH
  • 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 7926577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:50:06+00:00 2026-06-03T18:50:06+00:00

I would like to make a function that will create objects that have a

  • 0

I would like to make a function that will create objects that have a tiered relationship with one another. So each tier object holds its own set of children tier objects and shares a single parent object with all of its siblings. I am unfamiliar with any patterns but I would guess there is one to cover this type of scenario.

//constructor
var Tier = function(parent){
    if(parent===undefined)Tier.prototype.Parent = null;
    else if(parent.constructor===Tier)Tier.prototype.Parent = parent;
    else return //an error code;
    //each tiered object should contain it's own set of children tiers
    this.Children = [];
    //...
    //...additional properties...
    //...
    this.addChild = function(){
        this.Children.Push(new Tier(this));
    };
}

Tier.prototype.Parent; //I want this to be shared with all other tier objects on the same tier BUT this will share it between all tier objects regaurdless of what tier the object is on :(
Tier.prototype.Siblings; //should point to the parents child array to save on memory

Is it possible to create this kind of object where each tier object contains its own children and shares a parent object with its sibling but different tiers share the correct parents. I believe if I use something like the above when I add a new child it will make the Tier.prototype.Parent be the parent of that child but for all objects which isn’t the correct behaviour. I’m not sure how to get around this.

Any help much appreciated.

  • 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-03T18:50:07+00:00Added an answer on June 3, 2026 at 6:50 pm

    I don’t know if I’ve got it right, but try this:

    // class Tier
    function Tier(parentT) {
        var Parent;
    
        if((typeof parentT) == undefined) {
            Parent = null;
        } else if(parentT instanceof Tier) {
            Parent = parentT;
    
            parentT.addChildren(this);
        } else {
            Parent = null;
        }
    
        var Children = []; // private; if you want it public you can use this.Children
    
        this.addChildren = function(newChild) {
            Children.push(newChild);
        };
        this.getParent = function() {
            return Parent;
        };
        this.getChildren = function() {
            return Children;
        };
    }
    

    I was a bit confused by your question so there could be something wrong with my answer.

    As it is now, there can be a Tier with no parent. (no parameter) (var newTier = new Tier(););

    If you create a new Tier with a parameter it will be added to the children in the parent node (var parentTier = new Tier(); var child = new Tier(parentTier);).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make a ListBox function like a Grid . Each time
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make a php script that can capture a page from
I would like to make a JComboBox that has check boxes for items instead
In my C# winforms program I want to make an export function that will
I would like make an extension method for the generic class A which takes
I would like to make a LaTeX document with two tables of contents, like:
I would like to make a class where the client side (proxy) of the
I would like to make my drivers to install on x64 Windows without the
I would like to make an entire inline formset within an admin change form

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.