abstract-class-error

3.0.0 • Public • Published

AbstractConstructError

An error designed for being thrown when a class is instantiated, an object created, or a method is not overridden that, was intended to be abstract.

import AbstractConstructError from 'abstract-class-error';

class AbstractParent {
    constructor() {
        if (new.target === AbstractParent) {
            throw new AbstractConstructError('Cannot construct class AbstractParent instances directly');
        }

        if (this.abstractMethod === AbstractParent.prototype.abstractMethod) {
            throw new AbstractConstructError('Method "abstractMethod" must be overridden in class AbstractParent');
        }
    }

    abstractMethod() {}
}

Feedback ✉️

Website 🌐

js@jacobsmith.tech

https://github.com/limeandcoconut

@limeandcoconut 🐦

Cheers!

License

ISC, see license for details.

Usage

NPM

License

ISC, see LICENSE.md for details.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 3.0.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 3.0.0
    0
  • 2.0.0
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i abstract-class-error

Weekly Downloads

0

Version

3.0.0

License

ISC

Unpacked Size

6.48 kB

Total Files

7

Last publish

Collaborators

  • limeandcoconut