我试图在Javascript中命名一个类,当我初始化这个类时,类的名称出现了错误。
class e {. //SyntaxError: Unexpected token (13:6)
constructor(name, damage) {
this.name = name;
this.damage = damage;
}
}而且,如果我做了另一个,除了名称之外,所有的东西都是一样的,那么第二个类就没有错误。
class e { //SyntaxError: Unexpected token (13:6)
constructor(name, damage) {
this.name = name;
this.damage = damage;
}
}
class a { //all that comes up here is that a is not called in my program
constructor(and, what) {
this.and = and;
this.what = what;
}
}
当我添加第三类时,第二类不会发生任何错误。所以我不知道为什么会这样。
这是一个学校项目,我们正在使用Code.org的应用程序实验室,如果这有区别的话。
我从另一个程序中复制了一个类,并将其粘贴到这个程序中,只更改了名称,希望错误能够消失,但错误仍然存在。
发布于 2022-12-03 03:07:26
Code.org不支持class。https://forum.code.org/t/oop-and-class-impementation-tech-help/31755/3解释说,class并没有实现到所使用的解释器中,但是它给出了一个使用函数创建class的巧妙解决方案。它的工作方式似乎与class的工作方式相同,只是没有class语法。
https://stackoverflow.com/questions/74663038
复制相似问题