|
|
|
|
|
by ubertaco
3482 days ago
|
|
An approach I've seen is to have each class extend from some abstract base class (I know, OO blech) that looks like this: abstract class AbstractClassObject {
constructor(json?: any){
if (json){
this.updateFromJSON(json)
}
}
public updateFromJSON = (json: any): this => {
Object.assign(this, json);
return this;
}
}
That gives you the "magic" just by extending the base, while also allowing custom behavior for a given class (by overriding updateFromJSON). |
|