I am using the below line of code for one of the requirement -
class App {
constructor(){
this.obj = { val1: null, val2: '' };
}
}
And changed the above code to something below:
class App {
obj = { val1: null, val2: '' };
}
I could not see any difference between the above two code for the functionality aspects and both code snippets work the same way. I tried the same in the babeljs playground with preset "stage-3" and they are producing the same results.
Can you please let me know if any other differences between the above code and issues using one over the other?
this.obj = ...? Because withoutthis.you're declaring "a variableobjin whatever is the current scope", in a way that isn't even allowed under strict rules.ReferenceError: obj is not definedwhen you try to construct an object.this.?