[Javascript] Help with function containing array

Laurent Muchacho LaurentM at london.virgin.net
Wed Aug 11 03:21:13 CDT 2004


Hi 
 
The solution will be :
 

function division (id, name) {

            this.id = id;

            this.name = name;

} 

 

function department(id, name){

            this.id = id;

            this.name =name;

            this.divisions = new Array();

}

 

var departments = new Array();

// My Account departing containg id, name, and it's divisions

departments[0] = new department(1, "Accounting");

 

// My Accounting Divsions

departments[0].divisions[0] = new division(1, "Accounts Payable");

departments[0].divisions[1] = new division(2, "Account Recievable");

departments[0].divisions[2] = new division(3, "Payroll");

 

 
Laurent
 

-----Original Message-----
From: Pitre, Russell [mailto:RPITRE at shawmut.com]
Sent: 10 August 2004 20:06
To: javascript at LaTech.edu
Subject: [Javascript] Help with function containing array



Hello all-

 

I have these functions below.  I need to have a "department" object contain
an array of "division" objects.   I'm not sure how to
department[0].divisions with an array of divisions.  I'm thinking my problem
is how I'm setting "this.divisions" in the department object.

 

 

 

var departments = new Array();

var divisions = new Array();

 

function division (id, name) {

            this.id = id;

            this.name = name;

} 

 

function department(id, name, divisions){

            this.id = id;

            this.name =name;

            //  PROBLEM HERE!!!  I think

            this.divisions = divisions;

}

 

// My Accounting Divsions

divisions[0] = new division(1, "Accounts Payable");

divisions[1] = new division(2, "Account Recievable");

divisions[2] = new division(3, "Payroll");

 

// My Account departing containg id, name, and it's divisions

departments[0] = new department(1, "Accounting", divisions);

 

 



This E-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed.  If you have received this E-mail in error please notify the system manager.  This message contains confidential information and is intended only for the individual named.  If you are not the named addressee you should not disseminate, distribute or copy this E-mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20040811/2e1bac61/attachment.htm>


More information about the Javascript mailing list