Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
外部javascript数组初始化_Javascript_Html - Fatal编程技术网

外部javascript数组初始化

外部javascript数组初始化,javascript,html,Javascript,Html,我在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=addre

我在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> 

var myClients=新数组();
我的客户[0]={firstName:“John”,姓氏:“Doe”,Id:11,密码:1234,地址:“彩虹之上的某个地方”,电话号码:0523456789,电子邮件:yeah@gmail.com,键入:“常规”};
var账户=新账户(232,“年轻”);
var存款=新存款账户(232,“年轻”,1000,2555);
我的客户[0]。添加帐户(存款);
//clientAccounts.push(myClients[0]);
我初始化的每个客户端都应该有多个帐户。现在我不确定如何设置客户端的帐户数组。它是否应该是构造函数的一部分(括号内)?
因为现在我无法使用此数组或获取其数据(我正在尝试使用另一个js文件)。

为什么不实际使用构造函数:

myClients[0] = new client(11, "username", 1234, "regular", "John", "Doe", "Somewhere over the rainbow", "0523456789", "yeah@gmail.com");
那么“addAccount”方法应该可以工作了。
否则,您只有一个具有某些属性(attributes)的对象,而不是类client的对象。

为什么不实际使用构造函数:

myClients[0] = new client(11, "username", 1234, "regular", "John", "Doe", "Somewhere over the rainbow", "0523456789", "yeah@gmail.com");
那么“addAccount”方法应该可以工作了。
否则,您只有一个具有一些属性(attributes)的对象,而不是类client的对象。

希望我理解您的要求。它应该像oop一样。如何使数组成为客户端的属性?MyClient[0]。Accounts=[];这就是你想要的吗?我刚刚看到了第一个答案,所以你只是在问如何创建一个客户端实例?希望我理解你的要求。它应该像oop一样。如何使数组成为客户端的属性?MyClient[0]。Accounts=[];这就是你想要的吗?我刚刚看到了第一个答案,所以你只是问如何创建一个客户端实例?