I'm really new to JS and stackoverflow but not new to coding so forgive me if this has already been answered somewhere.
The reason to do it the second way would only be to improve the 'neatness' of the class. I'm wondering if there are performance trade-offs for readability by doing it that way.
To be more clear:
is there a performance loss from doing this:
class MyClass{
constructor(args){
this.UpdateClass(args);
}
UpdateClass(args){
this.firstVar = this.GetFirstVar();
this.secondVar = this.GetSecondVar(args);
}
GetFirstVar(){
return 420;
}
GetSecondVar(args){
return args.Cheesesteak;
}
}
Instead of doing this:
class MyClass{
constructor(args){
this.firstVar = this.GetFirstVar();
this.secondVar = this.GetSecondVar(args);
}
UpdateClass(args){
this.firstVar = this.GetFirstVar();
this.secondVar = this.GetSecondVar(args);
}
GetFirstVar(){
return 420;
}
GetSecondVar(args){
return args.Cheesesteak;
}
}
My interpretation of reading Google's js style guide was that they should always declare class variables inside the constructor because it's more computationally expensive to declare class variables inside another method, but is that still the case when the class method defines and/or updates every class variable without exception.