【发布时间】:2021-02-21 03:24:52
【问题描述】:
我想在我的节点应用程序中使用类,但我想知道是否有办法(比如在打字稿中)最小化类定义,例如:
class Rectangle(
constructor(height, width){
this.height = height;
this.width = width;
}
)
类似
class Rectangle(
constructor(height, width){}
)
所以我不需要将构造函数中的值分配给具有完全相同名称的变量。
【问题讨论】:
-
据我所知,答案是否定的;这只是 TypeScript 的一个特性。
-
@KenY-N 感谢您提供的信息。我读到您可以在 Node 应用程序中使用 TypeScript 类 - 如果不应该避免的话,我可能会尝试在我的 Node 应用程序中使用 TS 类。
标签: javascript node.js typescript class