Skip to content

Instantly share code, notes, and snippets.

@captain-yossarian
Created July 14, 2021 16:45
Show Gist options
  • Save captain-yossarian/8088d3e07b86b502abd5bdc77414d387 to your computer and use it in GitHub Desktop.
Save captain-yossarian/8088d3e07b86b502abd5bdc77414d387 to your computer and use it in GitHub Desktop.
type ClassType = new (...args: any[]) => any;
function merge(derived: ClassType, ...classRefs: ClassType[]) {
classRefs.forEach(classRef => {
Object.getOwnPropertyNames(classRef.prototype).forEach(name => {
const descriptor = Object.getOwnPropertyDescriptor(classRef.prototype, name)
// just add condition statement
if (name !== 'constructor' && descriptor) {
Object.defineProperty(
derived.prototype,
name,
descriptor
);
}
});
});
return derived;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment