Answer the question
In order to leave comments, you need to log in
How to access the overridden parent method of the parent (grandfather)?
There are the following classes:
class A {
foo() { alert("A"); }
}
class B extends A {
foo() { alert("B"); }
}
class C extends B {
foo() { alert("C"); }
bar() { /* Здесь я хочу вызвать A::foo() */ }
}
Answer the question
In order to leave comments, you need to log in
Through call / aply, A.prototype.foo.call(this), but no one does such nested classes in js because inheritance is prototype and works slowly
class A {
foo() { alert("A"); }
}
class B extends A {
foo() { alert("B"); }
}
class C extends B {
foo() { alert("C"); }
bar() { Reflect.getPrototypeOf(Reflect.getPrototypeOf(Reflect.getPrototypeOf(this))).foo(); }
}
const c = new C();
c.bar();
this.__proto__.__proto__.__proto__.foo.call(this)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question