乳清,我在识别javascript类时遇到问题

时间:2020-01-09 20:19:32

标签: javascript class eslint jslint

我创建如下的JavaScript class

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

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

...

但是我在jslint Excepted an identifier saw 'class'中有错误

在eslint中,出现the keyword 'Class' is reserved上的错误

1 个答案:

答案 0 :(得分:0)

您的代码存在一些问题:

  1. ema says一样,您需要将esversion设置为6。
  2. 类名应以印刷体字母开头,即使这可能不是导致出现错误消息的原因。
  3. constructor拼写错误
  4. 类方法不需要function关键字。
/*jshint esversion:6 */

class Contact {
  constructor (nom, prenom) {
      this.nom = nom;
      this.prenom = prenom;
  }
  afficher () {
      return "Nom : " + this.nom + " Prenom : " + this.prenom;
  }
}