我正在使用 C# 的 Jint 解释器 Jint
我想运行以下 JavaScript 代码。
class User {
constructor(name) { this.name = name; }
sayHi() { alert(this.name); }
}
...
但我总是遇到异常“第 1 行出现意外的保留字。”
我做错了什么?
C# 代码如下所示:
Engine jsEngine = new Engine();
jsEngine.Execute(script);
解决方案是按照描述构建类 here .
最佳答案
Jint is a Javascript interpreter for .NET which provides full ECMA 5.1 compliance
您看到的异常是由于 class
关键字引起的,它是在 ES6 中引入的,而 Jint 尚不支持。
关于javascript - 金特 "unexpected reserved word",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53011313/