A puzzle of ES6 grammar

recently, when writing React, to define a class method, I saw the following two writing methods: fun1 and fun2, both of which are not problematic to use. After reading the introduction guide of Master Ruan, I found that they are all written in fun1, so what"s the difference between the two?

class MyClass {
    name = 1;

    fun1() {
        console.log(this.name);
    }

    fun2 = () => {
        console.log(this.name);
    }
}
Mar.28,2021
Menu