I have a ES6 class with default parameters like so:
constructor({
// defaults
defaultOne = 'default value one',
defaultTwo = ['default','value','two],
defaultThree = 'default value three,
}) {
this.defaultOne = defaultOne
this.defaultTwo = defaultTwo
this.defaultThree = defaultThree
return this
}
When I create an instance of the class it works as expected when I provide values.
new Class({defaultOne: 'one',defaultTwo: ['t','w','o'], defaultThree: 'three'})
But when I instantiate an instance with no values:
new Class()
It throws an undefined error. This approach seems to work fine with standard function declarations/expressions. Any idea what I'm missing here?
Thanks in advance for any help on this.