How do I write a named arrow function in ES2015?

前端 未结 8 817
余生分开走
余生分开走 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();
    
    0 讨论(0)
  • 2020-11-22 17:12

    No. The arrow syntax is a shortform for anonymous functions. Anonymous functions are, well, anonymous.

    Named functions are defined with the function keyword.

    0 讨论(0)
提交回复
热议问题