How do I write a named arrow function in ES2015?

前端 未结 8 818
余生分开走
余生分开走 2020-11-22 16:29

I have a function that I am trying to convert to the new arrow syntax in ES6. It is a named function:

function sayHello(name) {
    console         


        
8条回答
  •  粉色の甜心
    2020-11-22 17:11

    You could skip the function part and the arrow part to create functions. Example:

     class YourClassNameHere{
    
       constructor(age) {
         this.age = age;
       }
    
       foo() {
         return "This is a function with name Foo";
       }
    
       bar() {
         return "This is a function with name bar";
       }
    
     }
    
    let myVar = new YourClassNameHere(50);
    myVar.foo();
    

提交回复
热议问题