How to Reset clear the values in a Typescript class
问题 How do I reset the values in a class in Typescript and ensure all the values are cleared? Is there a typescript function to do this? export class Product{ productId: number; productName: string; productDescription: string; } We have many classes with 50+ fields, looking for efficient way to conduct this. 回答1: Try like this: Working Demo productDetails: Product = { productId: 1, productName: "Apple", productDescription: "Fruit" }; reset() { this.productDetails = new Product(); } 回答2: YOu can