The following 2 snippets give same result. I wondered what is the real diffence in these 2 approaches and when should one be used instead of another way. Can someone help me out understanding the difference?
Case 1:
class Person{
constructor(name){
this.name = name;
}
printData(){
console.log(this.name);
}
}
Case 2 :
class Person{
constructor(name){
this.name = name;
this.printData = function(){
console.log(this.name);
}
}
}