-2

I create a JavaScript class like below:

class contact{
   constructeur(nom,prenom){
     this.nom = nom;
     this.prenom = prenom;
   }     

   function afficher(){
     return "Nom : " + this.nom + "Prenom : " + this.prenom;
   }

...

But I have an error in jslint Excepted an identifier saw 'class'

And in eslint gives an error on the keyword 'Class' is reserved

Michalis Garganourakis
  • 2,872
  • 1
  • 11
  • 24
Abdeloo07
  • 1
  • 3

1 Answers1

0

There are a few issues with your code:

  1. as ema says, you need esversion set to 6.
  2. class names should start with block letters, even though this may not be a cause for an error message.
  3. constructor is misspelled
  4. you don't need function keyword for class methods.
/*jshint esversion:6 */

class Contact {
  constructor (nom, prenom) {
      this.nom = nom;
      this.prenom = prenom;
  }
  afficher () {
      return "Nom : " + this.nom + " Prenom : " + this.prenom;
  }
}
ruffin
  • 16,507
  • 9
  • 88
  • 138
Addis
  • 2,480
  • 2
  • 13
  • 21