错误:无法读取未定义的属性push



我试图导入一个静态数组,将在两个不同的类中使用,但是当我试图通过数组参数推动参数时,它给了我一个错误。

第一课:

const ChargingStation = require('./chargingStation')           
class Scooter {
constructor(scooterID, color, speed, battery)
{
if (!scooterID) {
throw new Error("Please insert Scooter ID")
}
this.scooterID = scooterID
this.color = color
this.speed = speed
this.battery = battery
ChargingStation.allScooter.push(scooterID) // <--- This is the line that throws the error
} 
module.exports = Scooter

第二课:

class ChargingStation {
static allScooter = []
constructor() {}
module.exports = ChargingStation
}

我将根目录下的charingstation的名称更改为charingstation,重新启动IDE,它开始工作

最新更新