function user(name, level, job, apparel)
{
this.name = name;
this.state = "alive";
this.level = level;
this.job = job;
this.apparel = apparel;
}
player = new array();
player.push(new user("Main Player", 1, 1, "naked"));
document.write(player[0].name);
但它不起作用,没有任何回应。我做错了什么?
答案 0 :(得分:22)
您的代码中有拼写错误。
更改
player = new array();
到
player = new Array();
答案 1 :(得分:11)
我愿意
player = [];
而不是
player = new array();
作为健全性检查,请尝试:
document.write("Name: " + player[0].name);
答案 2 :(得分:7)
嗯,你有错误。它不是array
而是Array
。
答案 3 :(得分:1)
我试过这个并且工作了:
player = [{}];
而不是:
player = new Array();