【发布时间】:2022-11-28 17:07:59
【问题描述】:
所以我正在制作项目,当我尝试从父类获取参数时,它说 NaN,而另一个是 true。
这里的代码:
class transportasi {//class parent
constructor(nama,roda,pintu){
this.nama = nama
this.roda = roda
this.pintu = pintu
}
}
class mobil extends transportasi{//Class Children
constructor(roda,lampu){
super(roda)//the problem
this.lampu = lampu
}
jmlahfeature(){
return this.lampu + this.roda
}
}
const mobil1 = new mobil(2,4)//the problem
//I cant fill the value of roda only lampu
console.log("Hasil Perhitungan Feature mobil : " + mobil1.jmlahfeature())
我想要它所以我可以填充参数roda的值。所以它不会在控制台中说NaN。
【问题讨论】:
-
roda是transportasi构造函数的第二个参数。您只将 1 个参数传递给super()。
标签: javascript html