我尝试在我的node.js/express app上创建一个类.
它适用于基本的js/prototype模式,例如:
function MyClass() {
/* constructor code */
};
MyClass.prototype.myMethod = function() {
/* method code */
};
module.exports = MyClass;
Run Code Online (Sandbox Code Playgroud)
但我想使用class,constructor,extends,...关键字.
我试过了:
class MyClass {
constructor() {
/* constructor code */
}
myMethod() {
/* method code */
}
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用,错误是:
class MyClass {
^^^^^
SyntaxError: Unexpected reserved word
Run Code Online (Sandbox Code Playgroud)
我的命令行用于启动具有所有和声选项的应用程序:
node `node --v8-options | grep harmony | cut -d ' ' -f | xargs` my-app.js
Run Code Online (Sandbox Code Playgroud)
想要正确启动我的应用程序的想法吗?