Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class PrimarySchool extends School{
  constructror(name,level,numberOfStudents,pickupPolicy){
    super(name,level,numberOfStudents)
    this._pickupPolicy = pickupPolicy
  }
  get pickupPolicy(){
    return this._pickupPolicy
  }
}//end PrimarySchool 

>Solution :

There is a typo in the constructror in the PrimarySchool class. The correct word is constructor. Here’s a working sample code:

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 );

Do you use any IDE with syntax highlighting or a linter (e.g. ESLint)?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading