What is the equivalent to extending an arbitrary object with another one in TypeScript/ECMAScript6 ?
Essentially something like $.extend(target, src)
in jQuery or Ext.apply(target, src, defaults)
in ExtJS do.
I want to have a class constructor that simply applies a configuration object onto the object instance created by the constructor like so:
class Address {
country: string;
postCode: string;
city: string;
street: string;
houseNumber: string;
constructor (config : any) {
// simply tag all configuration onto the object,
// may be one, may be multiple, may be all properties
// of the resulting object instance
Object.apply(this, config); // ????
// jQuery.extend(this, config);
// Ext.apply(this, config);
this.init();
}
init () {
// do some initialization work ...
}
}
Or is the "object configuration pattern" deprecated for type-safe languages like TypeScript and ECMAScript6?
Is there a "new way" achieving the same flexibility?