【发布时间】:2021-08-27 10:34:12
【问题描述】:
class A {
#a = 1;
static #a = 2;
}
结果
-
Uncaught SyntaxError: redeclaration of private name #a在 Firefox 中 -
Uncaught SyntaxError: Identifier '#a' has already been declared在 Chrome 中
虽然
class A {
a = 1;
static a = 2;
}
在 Firefox 和 Chrome 中都有效
AFAIK 实例字段将安装在类实例上,而静态字段将安装在类对象本身上。他们并不冲突。为什么以前的代码无效?
【问题讨论】:
标签: javascript class static private class-fields