在课堂上使用箭头功能?

时间:2018-12-16 09:40:55

标签: javascript class arrow-functions

首先,我在开发工具中编写以下代码,并且一切正常:

class MyClass {
  constructor(name, verb, noun) {
     this.name = name;
     this.verb = verb;
     this.noun = noun;
  }

  myFunc() {
    return `${this.name}${this.verb}${this.noun}`
  }
}

但是,如果我将其更改为:

class MyClass {
  constructor(name, verb, noun) {
     this.name = name;
     this.verb = verb;
     this.noun = noun;
  }

  myFunc = () => {
    return `${this.name}${this.verb}${this.noun}`
  }
}

只需将传统功能转换为箭头功能,它会告诉我:

Uncaught SyntaxError: Unexpected token =

我不能在课堂上写箭头功能吗?

0 个答案:

没有答案