(Apologies if this is known, but I search a bunch of places and didn't find anything.)
Is there a good way to deal with a constructor of a derived class that is getting an options kind of value that needs to be merged with a defaults value? I started with something like this:
export class Foo extends Bar {
...
private options: any = {};
...
constructor(x: Something, y: SomethingElse, options: any = {}) {
this.options = $.extend({}, defaults, options);
super(this.options.blah);
...
}
}
This failed and I eventually resorted to:
constructor(x: Something, y: SomethingElse, options: any = {}) {
super(options.blah || defaults.blah);
this.options = $.extend({}, defaults, options);
...
}
which is duplicating functionality (and sloppy).
Hopefully I'm not the only one who ran into this problem and there's good way to do that?
(Apologies if this is known, but I search a bunch of places and didn't find anything.)
Is there a good way to deal with a constructor of a derived class that is getting an options kind of value that needs to be merged with a defaults value? I started with something like this:
This failed and I eventually resorted to:
which is duplicating functionality (and sloppy).
Hopefully I'm not the only one who ran into this problem and there's good way to do that?