有没有办法最小化Javascript中的类定义?

有没有办法最小化Javascript中的类定义?,javascript,node.js,typescript,class,Javascript,Node.js,Typescript,Class,我想在我的节点应用程序中使用类,但我想知道是否有一种方法(如在typescript中)可以最小化类定义,例如: class Rectangle( constructor(height, width){ this.height = height; this.width = width; } ) 差不多 class Rectangle( constructor(height, width){} ) 因此,我不需要将构造函数中的值赋给具有

我想在我的节点应用程序中使用类,但我想知道是否有一种方法(如在typescript中)可以最小化类定义,例如:

class Rectangle(

    constructor(height, width){
        this.height = height;
        this.width = width;
    }
)
差不多

class Rectangle(

    constructor(height, width){}
)
因此,我不需要将构造函数中的值赋给具有完全相同名称的变量。

否,仅是typescript功能。正如您在上的示例中所看到的,类

class Rectangle{
   constructor(private height:number, public width:number){ }
}
被传输到:

"use strict";
class Rectangle {
    constructor(height, width) {
        this.height = height;
        this.width = width;
    }
}
不过,您可以在NodeJS应用程序中使用TypeScript——假设您设置了一个构建步骤,将TypeScript代码转换/编译为javascript。或者,您也可以使用类似于库的程序来运行代码。

否,这是一项仅限typescript的功能。正如您在上的示例中所看到的,类

class Rectangle{
   constructor(private height:number, public width:number){ }
}
被传输到:

"use strict";
class Rectangle {
    constructor(height, width) {
        this.height = height;
        this.width = width;
    }
}

不过,您可以在NodeJS应用程序中使用TypeScript——假设您设置了一个构建步骤,将TypeScript代码转换/编译为javascript。或者,您可以使用类似于运行代码的库。

据我所知,答案是否定的;这只是TypeScript的一项功能。@KenY-N谢谢您提供的信息。我读到你可以在节点应用程序中使用TypeScript类——如果不应该避免的话,我可以尝试在我的节点应用程序中使用TS类;这只是TypeScript的一项功能。@KenY-N谢谢您提供的信息。我了解到您可以在节点应用程序中使用TypeScript类——如果不应该避免的话,我可以尝试在节点应用程序中使用TS类。