I know one of the difference is that instance variables of type Function automatically bind to the class. For example:
class Dog {
sound = 'woof'
bark() {
console.log(this)
}
boundBark = () => {
console.log(this)
}
}
const fido = new Dog()
fido.bark() // woof
fido.boundBark() // woof
const bark = fido.bark
bark() // undefined
const boundBark = fido.boundBark
boundBark() // woof
Dog { sound: 'woof', boundBark: [Function: boundBark] }
Dog { sound: 'woof', boundBark: [Function: boundBark] }
undefined
Dog { sound: 'woof', boundBark: [Function: boundBark] }
Why is this and are there other difference between these two ways of writing an instance function?