SyntaxError: 'super' keyword unexpected here when extending superclass
SyntaxError: 'super' keyword unexpected here when extending superclass
I have a super class School with properties name,level, and number of students
class School{
constructor(name,level,numberOfStudents){
this._name = name;
this._level = level
this._numberOfStudents = numberOfStudents
}
get name(){
return this._name;
}
get level(){
return this._level
}
get numberOfStudents(){
return this._numberOfStudents
}
}// end School() class
But when I extend that to a subclass PrimarySchool...
class PrimarySchool extends School{
constructror(name,numberOfStudents,pickupPolicy){
super(name,'primary',numberOfStudents)
this._pickupPolicy = pickupPolicy
}
get pickupPolicy(){
return this._pickupPolicy
}
}//end PrimarySchool
I get SyntaxError: 'super' keyword unexpected here. But I should be able to pass in 'primary' as the value for the parent class property level. Same with name and numberOfStudents. Even If I declare level in the sub-class constructor and don't even pass in a value, I get the same error:
class PrimarySchool extends School{
constructror(name,level,numberOfStudents,pickupPolicy){
super(name,level,numberOfStudents)
this._pickupPolicy = pickupPolicy
}
get pickupPolicy(){
return this._pickupPolicy
}
}//end PrimarySchool
PrimarySchool
class 中的 constructror
有错别字。正确的单词是 constructor
。这是一个有效的示例代码:
class School{
constructor(name,level,numberOfStudents){
this._name = name;
this._level = level
this._numberOfStudents = numberOfStudents
}
get name(){
return this._name;
}
get level(){
return this._level
}
get numberOfStudents(){
return this._numberOfStudents
}
}// end School() class
class PrimarySchool extends School{
constructor(name,numberOfStudents,pickupPolicy){
super(name,'primary',numberOfStudents)
this._pickupPolicy = pickupPolicy
}
get pickupPolicy(){
return this._pickupPolicy
}
}//end PrimarySchool
const school = new PrimarySchool( 'NY School', 2137, true );
console.log( school );
您是否使用带有语法高亮显示或 linter(例如 ESLint)的 IDE?
I have a super class School with properties name,level, and number of students
class School{
constructor(name,level,numberOfStudents){
this._name = name;
this._level = level
this._numberOfStudents = numberOfStudents
}
get name(){
return this._name;
}
get level(){
return this._level
}
get numberOfStudents(){
return this._numberOfStudents
}
}// end School() class
But when I extend that to a subclass PrimarySchool...
class PrimarySchool extends School{
constructror(name,numberOfStudents,pickupPolicy){
super(name,'primary',numberOfStudents)
this._pickupPolicy = pickupPolicy
}
get pickupPolicy(){
return this._pickupPolicy
}
}//end PrimarySchool
I get SyntaxError: 'super' keyword unexpected here. But I should be able to pass in 'primary' as the value for the parent class property level. Same with name and numberOfStudents. Even If I declare level in the sub-class constructor and don't even pass in a value, I get the same error:
class PrimarySchool extends School{
constructror(name,level,numberOfStudents,pickupPolicy){
super(name,level,numberOfStudents)
this._pickupPolicy = pickupPolicy
}
get pickupPolicy(){
return this._pickupPolicy
}
}//end PrimarySchool
PrimarySchool
class 中的 constructror
有错别字。正确的单词是 constructor
。这是一个有效的示例代码:
class School{
constructor(name,level,numberOfStudents){
this._name = name;
this._level = level
this._numberOfStudents = numberOfStudents
}
get name(){
return this._name;
}
get level(){
return this._level
}
get numberOfStudents(){
return this._numberOfStudents
}
}// end School() class
class PrimarySchool extends School{
constructor(name,numberOfStudents,pickupPolicy){
super(name,'primary',numberOfStudents)
this._pickupPolicy = pickupPolicy
}
get pickupPolicy(){
return this._pickupPolicy
}
}//end PrimarySchool
const school = new PrimarySchool( 'NY School', 2137, true );
console.log( school );
您是否使用带有语法高亮显示或 linter(例如 ESLint)的 IDE?