abstract-class-js

Abstract class enforcement in JS

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
abstract-class-js
001.3.05 years ago5 years agoMinified + gzip package size for abstract-class-js in KB

Readme

abstract-js
Abstract class enforcement in JS

Getting Started

Simply import the module as a class. To create an abstract class, use the imported module as its superclass.
const AbstractClass = require("abstract-class-js");

class Parent extends AbstractClass {

    constructor() {
        super(Parent, ["test"]);
    }

}

class Child extends Parent {
    constructor(){
        super();
    }
    test(){
        console.log("Hello, World!");
    }
}

To add 'required' implementations, simply construct the class with an arugment after the class name itself.
class Parent extends AbstractClass {

    constructor() {
        super(Parent, ["required", "methods", "go", "here"]);
    }

}

This library also provides a convinience method called `super() for all Object` types. This allows you to check if a class belongs to an abstract class.

Errors

An attempt to initiate an abstract class will result an error.
Error: Abstract class Parent cannot be cannot be instantiated without a subclass implementation.

An incomplete implementation of a class will result an error as well.
Error: Classes extending abstract class Parent must implement test