我在识别javascript上的类时遇到了一个问题

我在识别javascript上的类时遇到了一个问题,javascript,class,eslint,jslint,Javascript,Class,Eslint,Jslint,我创建了一个JavaScript类,如下所示: class contact{ constructeur(nom,prenom){ this.nom = nom; this.prenom = prenom; } function afficher(){ return "Nom : " + this.nom + "Prenom : " + this.prenom; } ... 但是我在jslint中有一个错误,除了一个标识符saw

我创建了一个JavaScript
,如下所示:

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

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

...
但是我在jslint
中有一个错误,除了一个标识符saw'class'


在eslint中,在
上给出了一个错误,关键字“Class”是保留的

您的代码有一些问题:

  • 同样,您需要将esversion设置为6
  • 类名应以正楷开头,即使这可能不是产生错误消息的原因
  • 构造函数
    拼写错误
  • 类方法不需要
    function
    关键字

  • 函数是否应该在类中?是否在ESLint中启用了ES6语法?应该有一个选项
    ecmaVersion
    类的构造函数也应该用英语拼写,而不是外语。是的,我有,我已经有了选项ecmaVersiontoolbar@Addis是的
    /*jshint esversion:6 */
    
    class Contact {
      constructor (nom, prenom) {
          this.nom = nom;
          this.prenom = prenom;
      }
      afficher () {
          return "Nom : " + this.nom + " Prenom : " + this.prenom;
      }
    }