javascript - Javascript 闭包编译器
问题描述
我正在学习为 javascript 使用谷歌闭包编译器,但有奇怪的编译错误
我收到这条消息:
ctest2.js:31: ERROR - [JSC_PARSE_ERROR] Parse error. '(' expected
31| testArray = [];
^
1 error(s), 0 warning(s)
如果我将该行注释掉,则编译工作。
这是整个班级:
class TestA
{
testArray = []; // Comment this out to get rid of error
constructor()
{
this.testArray.push( { name : "joe", age : 70 } );
this.testArray.push( { name : "mike", age : 50 } );
this.testArray.push( { name : "bob", age : 33 } );
}
testLoop()
{
for(const test of this.testArray)
{
console.log(" >>> " + test.name + " " + test.age);
}
}
}
为什么编译不正确?
解决方案
原因是因为 google-closure-compiler 尚不支持在类中声明的那种变量。但例如在 google chrome 中支持它
推荐阅读
- c# - 如何从列表视图获取图像并将其保存到文件夹
- python - 从类中调用函数
- go - `go run: cannot run non-main package`作为非特权用户
- python - Django 静态文件服务与 React Router 冲突
- opengl - 为什么这些opengl矩形看起来不一样?
- api - 在 ASP Net Core API 中使用 NLog 进行 Elasticsearch 日志记录失败
- scheme - 这个 Scheme 代码如何返回值?
- c# - 如何将字典转换为数据表?
- bash - 打开 SQLite 控制台并在不退出的情况下执行 SQL
- javascript - 如何在构造函数中执行异步函数?