Javascript闭包编译器

Javascript闭包编译器,javascript,google-closure-compiler,Javascript,Google Closure Compiler,我正在学习使用googleclosurecompilerforjavascript,但有一个奇怪的编译错误 我得到这个信息: ctest2.js:31: ERROR - [JSC_PARSE_ERROR] Parse error. '(' expected 31| testArray = []; ^ 1 error(s), 0 warning(s) 如果我评论那行,编译就行了 下面是全班同学: class TestA { testArray = [];

我正在学习使用googleclosurecompilerforjavascript,但有一个奇怪的编译错误

我得到这个信息:

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闭包编译器中还不受支持。但是它在google chrome中是受支持的,因为在类主体中放置赋值是无效的JavaScript。类字段仍然是唯一的,您需要在选项中显式地启用对该语法的支持(如果gcc完全支持它们的话)。我在google chrome中使用了这段代码,没有任何问题。是的,chrome的js引擎已经实现了这一建议