金特 "unexpected reserved word"

Jint "unexpected reserved word"

我正在使用 C# 的 Jint 解释器Jint

我想要运行下面的JavaScript代码。

class User {
  constructor(name) { this.name = name; }
  sayHi() { alert(this.name); }
}
...

但我总是遇到异常"unexpected reserver word in line 1."

我做错了什么?

C# 代码如下所示:

Engine jsEngine = new Engine();
jsEngine.Execute(script);

解决方案是按照 here 所述构建 class。

Jint is a Javascript interpreter for .NET which provides full ECMA 5.1 compliance

您看到的异常是因为 class 关键字,它是在 Jint 尚不支持的 ES6 中引入的。