Sep 5, 2018 · 1 min read
That 2nd approach is actually an error.. But if you meant this below, there is a difference:
class Cat {
constructor () {
// 2nd approach
this.walking = () => console.log('cat walk');
}
// 1st approach
meow () {
console.log(‘meow’)
}
}
The walking method is actually part of the new Cat, rather than the new Cat’s prototype.

If we change the prototype of our new cat (never do this!), it will be able to walk, but not meow.
It’s worth noting that a new walking function is created for every new cat. In contrast, the prototype is shared by all the cats, and only the context (what this points to) is unique for new cats.
In practice, though, cat.walking() and cat.meow() both do what you would expect. So, use both approaches when it makes sense to (set properties in the constructor using this , and methods outside of the constructor where possible).