1

I have an external client in a js file.

function client(Id,userName,code,type, firstName, SurName, address, phoneNum, Email)
{
    this.Id = Id;
    this.userName = userName;
    this.code = code;
    this.firstName=firstName;
    this.SurName=SurName;
    this.ddress=address;        
    this.phoneNum=phoneNum;
    this.Email =Email;
    this.clientAccounts = [];

    this.addAccount = function(account)
    {
        this.clientAccounts.push(account);
    };

    }

and I have an html page. In it I have a script:

<script type="text/javascript">
var myClients =new Array();
myClients[0]= {firstName:"John", SurName: "Doe" ,Id:11,Password:1234, Address:"Some where over the rainbow", Pnumber:0523456789, Email:"[email protected]", Type: "regular"};
var account = new account(232, "young");
var deposit = new depositAccount(232, "young", 1000, 2555);
myClients[0].addAccount(deposit);

//clientAccounts.push(myClients[0]);
</script> 

Each client I initialize should have multiple accounts. Now I'm not sure how do I set the account array of the client. should it be a part of the constructor(inside the parentheses)? Because right now I can't use this array or get its data (I'm trying using another js file).

4
  • 2
    wish i understood what you were asking. Commented Jan 15, 2014 at 21:28
  • It's supposed to be like oop. How do I make the array a property of client? Commented Jan 15, 2014 at 21:30
  • myClients[0].Accounts = []; is that what you are looking for? Commented Jan 15, 2014 at 21:32
  • 1
    I just saw the first answer, so you are just asking how to create an instance of Client? Commented Jan 15, 2014 at 21:33

1 Answer 1

4

Why don't you actually make use of the constructor:

myClients[0] = new client(11, "username", 1234, "regular", "John", "Doe", "Somewhere over the rainbow", "0523456789", "[email protected]");

Then the "addAccount" method should work. Otherwise you just have an object with some properties(attributes), but not of the class client.

Sign up to request clarification or add additional context in comments.

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.