Convert javascript class instance to plain object preserving methods
问题 I want to convert an instance class to plain object, without losing methods and/or inherited properties. So for example: class Human { height: number; weight: number; constructor() { this.height = 180; this.weight = 180; } getWeight() { return this.weight; } // I want this function to convert the child instance // accordingly toJSON() { // ??? return {}; } } class Person extends Human { public name: string; constructor() { super(); this.name = 'Doe'; } public getName() { return this.name; } }