JavaScript,为什么会出现错误;函数add";中未定义数组;

JavaScript,为什么会出现错误;函数add";中未定义数组;,javascript,object,Javascript,Object,这是我的密码 var chars = new function() { this.array = new Array(0); this.add = function(x, y, speed, size, color, ai) { this.array[array.length] = {x: x, y: y, size: size, color: color, ai: ai}; } } 在第35行,函数add I中唯一一行出现错误“array is not defined”为

这是我的密码

var chars = new function() {
  this.array = new Array(0);
  this.add = function(x, y, speed, size, color, ai) {
    this.array[array.length] = {x: x, y: y, size: size, color: color, ai: ai};
  }
}
在第35行,函数add I中唯一一行出现错误“array is not defined”为什么会发生这种情况,是的,我尝试过

chars.array[array.length] = {x: x, y: y, size: size, color: color, ai: ai};
您必须将其修复为:

var chars = new function() {
    this.array = new Array(0);
    this.add = function(x, y, speed, size, color, ai) {
        this.array[this.array.length] = {x: x, y: y, size: size, color: color, ai: ai};
    }
}
我已将
this.array[array.length]
更改为
this.array[this.array.length]
您必须将其修复为:

var chars = new function() {
    this.array = new Array(0);
    this.add = function(x, y, speed, size, color, ai) {
        this.array[this.array.length] = {x: x, y: y, size: size, color: color, ai: ai};
    }
}
我已将
this.array[array.length]
更改为
this.array[this.array.length]
您必须将其修复为:

var chars = new function() {
    this.array = new Array(0);
    this.add = function(x, y, speed, size, color, ai) {
        this.array[this.array.length] = {x: x, y: y, size: size, color: color, ai: ai};
    }
}
我已将
this.array[array.length]
更改为
this.array[this.array.length]
您必须将其修复为:

var chars = new function() {
    this.array = new Array(0);
    this.add = function(x, y, speed, size, color, ai) {
        this.array[this.array.length] = {x: x, y: y, size: size, color: color, ai: ai};
    }
}

我已将
this.array[array.length]
更改为
this.array[this.array.length]
我建议您使用该方法。push方法将值附加到数组中

 this.array.push({x: x, y: y, size: size, color: color, ai: ai});

我建议你们使用这个方法。push方法将值附加到数组中

 this.array.push({x: x, y: y, size: size, color: color, ai: ai});

我建议你们使用这个方法。push方法将值附加到数组中

 this.array.push({x: x, y: y, size: size, color: color, ai: ai});

我建议你们使用这个方法。push方法将值附加到数组中

 this.array.push({x: x, y: y, size: size, color: color, ai: ai});

抱歉,我无法使代码格式正常工作。抱歉,我无法使代码格式正常工作。抱歉,我无法使代码格式正常工作。抱歉,我无法使代码格式正常工作。