Search code examples
javascriptkeywordsuper

JavaScript - super() keyword unexcepted


I'm getting in trouble with a small problem and I wish that somebody can help me resolving this fast. Here is my code :

class Client {
    /**
   * @param {ClientOptions} [options] Options for the client
   */
  constructor(options = {}) {
    super();
    this.lnk = "https://marketpala.glitch.me";
    this.endpoints = [
        "/commandes.json",
        "/users.json",
        "/blacklist.json",
        "/infov.json",
        "/reserved.json"
    ]
  }
}

Here is the code to export the client :

module.exports = {
    Client: require('./client/Client')
}

Here is the code I use to test my client :

const tst = require('./palamazon')
let t = new tst.Client()

And here is the error I get :

super();
    ^^^^^

SyntaxError: 'super' keyword unexpected here

Hope somebody can help me!

(I'm coding in javascript)


Solution

  • Super keyword is used in inherited classes to use their properties inside the child class. Your class is not extended from any other classes, so super is not accepted.

    By calling the super() method in the constructor method, we call the parent's constructor method and gets access to the parent's properties and methods:

    If your class is not being extended from any other classes, the super method must be deleted.

    Check some details here.