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 6863121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:44:38+00:00 2026-05-27T02:44:38+00:00

I have decided (whether bravely or foolishly remains to be seen) decided to increase

  • 0

I have decided (whether bravely or foolishly remains to be seen) decided to increase my javascript skills beyond the use of alerts and I’ve
been looking at using javascript business objects with the hope of creating a useful library of objects that I can then manipulate with JSON or XML
further on down the line.

The basic concepts are straightforward enough but I can’t seem to find an example anywhere of how to expose a property of an object that is a collection of
a different type of object.

For instance if I have a “Department” object I would like to have an “Employees” property which is a collection of “Employee” objects.

I’m from a .Net background so I might be coming at this with the completely wrong mindset here but if I am I’d like to learn the right way to approach this.

Is the concept still applicable in javascript, can a property of a javascript object be a collection of another type of object? Does the concept of a collection even exist (I’d like to be able to enumerate through the collection too) or should I be thinking in terms of arrays or something else?

Here is some pseudo code which should illustrate what I’m aiming for:

function Department (Name) 
{
    this.DepartmentName=Name;
    this.Employees = null; // How do I initialise a property to be a collection of Employee objects?
    }

function Employee(FirstName, Surname)
{
    this.EmployeeName = Firstname + ' ' + Surname;
}

Department.prototype.addEmployee = function (Firstname, Surname) 
{
    //In here I want to create an Employee object and add it to an
    //'Employees' property of the department object
}
  • 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-05-27T02:44:39+00:00Added an answer on May 27, 2026 at 2:44 am

    There is no real “list of objects of a specific type” in JavaScript. You seem to just want an array, which is a “collection” (basically an object) with numeric keys and values which can be everything (JavaScript is dynamic, so there is no easy way to force a collection to contain only items of one type, but you should never need to anyway):

    function Department (Name) 
    {
        this.DepartmentName = Name;
        this.Employees = []; // empty array
    }
    

    Then in the prototype function, you can:

    1. create a new instance (object) of type Employee
    2. add it to this.Employees

    Like:

    Department.prototype.addEmployee = function (Firstname, Surname) 
    {
        // adds to the end of the array
        this.Employees.push(new Employee(Firstname, Surname));
    };
    

    You can access the Employee objects like this.Employees[0], etc.

    Don’t forget the semicolon at the end of the prototype function. It’s a function expression, and it’s good practice to terminate function expressions with a semicolon. Function declarations (like for Department and Employee), on the other hand, do not need those. The difference is that the prototype function is used as an expression in the assignment statement.

    Moreover, CapitalCase is usually used for constructors (Employee); regular variable names are usually names in camelCase.

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

Sidebar

Related Questions

After several failed attempts using ExtJS I have now decided to use javascript.The requirement
I have started a new web application and have decided to use jquery as
I have decided (whether it's for better or for worse), to start learning the
I have decided to use IoC principles on a bigger project. However, i would
How do you decided whether to use nvarchar or nchar ? For instance I
I have been looking at the feasibility of porting over an intranet web app
I have decided to use Spring, Hibernate, and Restlet to create a web service.
I have been looking into perlin noise for an application I'm working on its
I have decided to add some validation to my combobox, what I'm trying to
I have decided to start using unit testing in PL/SQL, since it could be

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.