You could combine destructuring with default params. I'm currently doing it like that:
class Parent {
constructor(args = {}){
//destructure what you need here
let {
a = "default a",
b = "default b",
c = "default c"
} = args
this.a = a
this.b = b
this.c = c
}
}
class Child extends Parent {
constructor(args = {}){
//pass args object
super(args)
//destructure what you need here
let {
d = "default d",
e = "default e"
} = args
this.d = d
this.e = e
}
}
let parent = new Parent({
a: "Param A",
b: "Param B",
c: "Param C"
})
let child = new Child({
a: "Param A",
e: "Param E",
c: "Param C"
})
console.log(parent)
console.log(child)
This way changes your object declaration a bit, since you allways passing variables as a single args object.
You may consider checking for type object though since it wont throw an error if you'll pass something else - instead it would just use default values. But i feel that should count as exprected behaivior.
In the same manner args = {}
handles the no arguments case, but it's not striclty neccessary either, but a good habbit, if you'll for example accidently pull something from args later in non destructuring manner.
Here's a bin: JSBin
constructor()
or shouldn't it better beconstructor(a, b, c)
like in Parent?