I want to create a wrapper mechanism: we wrap c
so new new object w
has own properties and methods but c
's are also accessible.
// Note: this class might be from an external lib
class C {
f() {
console.log('f (original)');
this.p = 'p';
}
}
class W {
f() {
console.log('f (new)');
super.f(); // TypeError: (intermediate value).f is not a function
console.log(this.p);
}
}
// Note: this value is external for us
const c = new C();
const w = Object.create(null, Object.getOwnPropertyDescriptors(W.prototype));
Object.setPrototypeOf(w, c);
w.f(); // expected:
// f (new)
// f (original)
// p
Do I do this in correct manner?
Why is error happen?
Update: P.S. I do understand that I could use composition but I want to understand the source of error.