简体   繁体   English

Javascript 闭包编译器

[英]Javascript closure compiler

I am learning to use google closure compiler for javascript but have strange compile error我正在学习为 javascript 使用谷歌闭包编译器,但有奇怪的编译错误

I get this message:我收到这条消息:

ctest2.js:31: ERROR - [JSC_PARSE_ERROR] Parse error. '(' expected
31|  testArray = [];
                 ^

1 error(s), 0 warning(s)

If I comment that line out the compile works.如果我将该行注释掉,则编译工作。

here's the whole class:这是整个 class:

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);
}

}

}

Why isn't it compiling properly?为什么编译不正确?

Reason is because that kind of variable declaring inside class is not yet supported in the google-closure-compiler.原因是在 google-closure-compiler 中尚不支持在 class 中声明的那种变量。 But it's supported for example in google chrome但例如在 google chrome 中支持它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM