i have this situation
import assert from 'assert'
class A {
static x = 0
static a () {
return A.x
}
}
class B extends A {
static x = 1
}
assert.equal(B.a(), 1)
i need to retrive static value in derived class from base class in Js es6. but, i can't find a way,
the assertion will fails with
AssertionError [ERR_ASSERTION]: 0 == 1
what's the right way to do this?
Here, you're asking for A.x directly. You should call this.x to get A.x when you are on an object of kind A and to get B.x when you are on an object of kind B.
Just make following changes and it should work fine:
static a () {
return this.x;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With