Skip to content

Instantly share code, notes, and snippets.

@SuperPaintman
Last active October 14, 2016 12:07
Show Gist options
  • Save SuperPaintman/f365300e5abaffcae7357c611bbc9ca1 to your computer and use it in GitHub Desktop.
Save SuperPaintman/f365300e5abaffcae7357c611bbc9ca1 to your computer and use it in GitHub Desktop.
export class AbstractClass {
constructor(constructor, name) {
if (!name) {
name = constructor.name;
}
if (this.constructor === AbstractClass) {
throw new Error(`Cannot create an instance of the abstract class "AbstractClass"`);
}
if (this.constructor === constructor) {
throw new Error(`Cannot create an instance of the abstract class "${name}"`);
}
}
}
export abstract class AbstractClass {
constructor(constructor: Function, name?: string) {
if (!name) {
name = constructor.name;
}
if (this.constructor === AbstractClass) {
throw new Error(`Cannot create an instance of the abstract class "AbstractClass"`);
}
if (this.constructor === constructor) {
throw new Error(`Cannot create an instance of the abstract class "${name}"`);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment