abstract-method

A tiny utility for creating abstract methods.

Usage no npm install needed!

<script type="module">
  import abstractMethod from 'https://cdn.skypack.dev/abstract-method';
</script>

README

abstract-method

A tiny utility for creating abstract methods.

Install

npm i --save abstract-method

Usage

import abstract from 'abstract-method';

class MyClass {
  /* ... */
}

// this creates 2 abstract methods 'foo' and 'bar'
abstract(MyClass, 'foo', 'bar');

Getter & Setter

abstract.getter(MyClass, 'foo');
abstract.setter(MyClass, 'bar');

Static Method

abstract.static(MyClass, 'foo');

Static Getter & Setter

abstract.static.getter(MyClass, 'foo');
abstract.static.setter(MyClass, 'bar');

Error

class Animal {}
abstract(Animal, 'walk');

var animal = new Animal();
animal.walk(); // throws NoImpl error
class Snake extends Animal {}
var snake = new Snake();
snake.walk(); // throws NoImpl error
class Dog extends Animal {
  walk() {
    // implementation
  }
}
var dog = new Dog();
dog.walk(); // OK