如何重置清除 Typescript 类中的值 [英] How to Reset clear the values in a Typescript class
本文介绍了如何重置清除 Typescript 类中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Typescript 中重置类中的值并确保清除所有值?有没有打字稿功能可以做到这一点?
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;
}
我们有许多包含 50 多个字段的类,正在寻找有效的方法来执行此操作.
We have many classes with 50+ fields, looking for efficient way to conduct this.
推荐答案
试试这个:
productDetails: Product = {
productId: 1,
productName: "Apple",
productDescription: "Fruit"
};
reset() {
this.productDetails = new Product();
}
这篇关于如何重置清除 Typescript 类中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文