1

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)

koro
  • 111
  • 1
  • 13
  • Does this answer your question? [super keyword unexpected here](https://stackoverflow.com/questions/39263358/super-keyword-unexpected-here) – Craicerjack Mar 03 '20 at 10:28
  • 1
    why would you want to call super() in this case? – HRK44 Mar 03 '20 at 10:30
  • @KoroBaka If you're following some kind of tutorial and it told you to write super(), it is highly likely you were supposed to extend Client from something. In fact based on the way you're using the class (just overwriting the constructor and adding nothing else) I'd say that it is even likely. – Michael Mar 03 '20 at 11:05

3 Answers3

4

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.

Nitheesh
  • 19,238
  • 3
  • 22
  • 49
0

As you are not extending any class so the super is not expected, super calls parent class constructor but in this case there is no parent to this class.

Ajay Kumar
  • 99
  • 6
0

super() is used to call the original method on the parent class when you are extending one class from another like so,

class MyFirstTestClass {
    constructor() {
        console.log("Hello");
    }
}

class MySecondTestClass extends MyFirstTestClass {
    constructor() {
        super();

        console.log("World");
    }
}

const test = new MySecondTestClass();

This will output Hello and then World. Without calling super(), only World would be outputted because the constructor on the second class would override the constructor on the first.

The class you wrote does not extend from another class, and so super() has no parent class to call to.

You should be able to fix your problem by either inheriting from another class if that was your intention, or by simply deleting the line where you call super().

Mohammad Faisal
  • 2,144
  • 15
  • 26
Michael
  • 1,075
  • 1
  • 10
  • 24