This is a bit of a tricky question about destructuring ES6 using the default javascript object constructor.
I would like to get a destructured parameters object with default values for my object constructor
so i did it
function bla({a=3,b=6}={}){
this.a=a;
this.b=b;
console.log(`this.a::'${this.a}' this.b::'${this.b}' a::'${a}' b::'${b}'`);
}
let myObject= new bla({a:1});
console.log(`myObject.a::'${myObject.a}' myObject.b::'${myObject.b}'`);
I know that what I did works. However, you can see that this is a bit of code smell, because every time I need to add a new parameter to the constructor (for example, {newParameter = 3}), I also need to go down and add the corresponding line similar to this in the constructor body
this.newParameter=newParameter;
Is there an even more elegant way to add a destructed parameter with a default value that is automatically bound to "this".