UNPKG

sussy-util

Version:
32 lines (31 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Error_1 = require("../Error"); class AbstractClass { constructor(Constructor) { const isClass = (arg) => { if (typeof arg !== 'function') { return false; } try { arg(); } catch (e) { if (/^Class constructor/.test(e.message)) { return true; } } return false; }; if (!isClass(Constructor)) throw new TypeError('Constructor must be the constructor of a class.'); if (this.constructor === Constructor) { // if constructor is the same as the instance constructor then we know that a user is trying to make a new instance of an abstract class throw new Error_1.AbstractClassInstanceCallError("You can't instantiate a new instance of a abstract class."); } if (this.constructor === AbstractClass.prototype.constructor) { throw new Error_1.AbstractClassInstanceCallError("You can't instantiate a new instance of a abstract class."); } } } exports.default = AbstractClass;