这是代码:
// The Person constructor
function Person(name, age) {
this.name = name;
this.age = age;
}
// Now we can make an array of peoples
var family = new Array();
family[0] = Person("alice", 40);
family[1] = Person("bob", 42);
family[2] = Person("michelle", 8);
family[3] = Person("timmy", 6);
// loop through our new array
for ( i=0; i < family.length; i++; ) {
console.log(family[i].name)
};
该脚本的预期输出为:
alice
bob
michelle
timmy
但输出是:
未捕获的类型错误:无法读取未定义的属性“名称”(匿名函数)