I want a possibility to copy all properties/methods of a class instance:
class A { get prop1() { return 1; } get prop2() { return 2; } doStuff() { return this.prop1 + this.prop2; } } class B extends A { get prop1() { return 5; } } class AWrapper { constructor(a) { // [1] Copy all methods/propertys of a this.doStuff = () => a.doStuff() + 42; } } const a = new A(); const b = new B(); const wA = new AWrapper(a); const wB = new AWrapper(b); console.log(a.prop1(), wA.prop1(), wB.prop1()); // 1, 1, 5 console.log(a.doStuff(), wA.doStuff()); // 3, 45 I could copy each method/property by hand, but is there a simple command for [1], such that wA has the same signature as a?
class AWrapper extends A { ... })a. I.e. assumeais just an instance of A, not A directly. I've edit the example