Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 139800

Hacking the import statement to extend an inherited class

$
0
0

In a library that I wish to extend without modifying its code, several classes inherit from the same imported one. That is in this BaseClass I would need to overwrite a specific method.

  • In the library (written in TypeScript) :
import { BaseClass } from './base_class';
export class ClassA extends BaseClass {}

import { BaseClass } from './base_class';
export class ClassB extends BaseClass {}
…
  • In the external extension I wish to write :
import { BaseClass } from 'library';
export class ExtendedBaseClass extends BaseClass {
    oneMethod() {
         const data = BaseClass.prototype.oneMethod.call(this);
         // make additional things with data
         return data;
    }
}

Is there a way for this new ExtendedBaseClass to become the parent of all ClassXs ? At least in a new extended and re-exported version of them without the need to copy their internal code.


Viewing all articles
Browse latest Browse all 139800

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>