I've been exploring different coding styles in TypeScript recently.
When it comes to initializing an object from a class, what are the advantages and disadvantages of these two code styles in TypeScript?
class Class3 {
// members
private readonly m1: Class1;
private readonly m2: Class2;
constructor({
_m1 = new Class1(),
_m2 = new Class2()
}:{_m1:Class1, _m2:Class2}){
this.m1 = _m1;
this.m2 = _m2;
}
public foo() {
console.log("Hello World a");
}
}
class Class3 {
// members
private readonly m1: Class1;
private readonly m2: Class2;
constructor() {
this.m1 = new Class1();
this.m2 = new Class2();
}
public foo() {
console.log("Hello World b");
}
}