簡體   English   中英

外部javascript數組初始化

[英]External javascript array initializing

我在js文件中有一個外部客戶端。

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);
    };

    }

而且我有一個html頁面。 在其中我有一個腳本:

<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:"yeah@gmail.com", 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> 

我初始化的每個客戶端都應該有多個帳戶。 現在,我不確定如何設置客戶的帳戶數組。 它應該是構造函數的一部分(在括號內)嗎? 因為現在我無法使用此數組或獲取其數據(我正在嘗試使用另一個js文件)。

您為什么不真正使用構造函數:

myClients[0] = new client(11, "username", 1234, "regular", "John", "Doe", "Somewhere over the rainbow", "0523456789", "yeah@gmail.com");

然后,“ addAccount”方法應該起作用。 否則,您只有一個具有某些屬性(屬性)的對象,而不是類客戶端的對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM