【发布时间】:2020-04-30 04:19:04
【问题描述】:
我很好奇如何调用一个类的one-level parent (not the oldest one) 来获取它的static 值并与当前类静态值相连接。例如:
class Grandpa {
static xxx = [1,2]
}
class Father extends Grandpa {
static xxx = [...Grandpa.xxx, 3] // how to get Grandpa's xxx value without mention Grandpa before .xxx?
}
class Child extends Father {
static xxx = [...Father.xxx, 4] // how to get Father's xxx value without mention Father before .xxx?
}
console.log(Child.xxx) // [1,2,3,4]
怎么做?
【问题讨论】:
-
你试过
super.xxx吗? -
@jfriend00 这是一个
static属性,我可以用super调用它吗? -
嗯,有一个 here 的例子。我自己从未尝试过。你可以写一个 10 行的测试脚本来试试。
标签: javascript oop ecmascript-6