abstract-method

0.1.0 • Public • Published

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

Install

npm i abstract-method

DownloadsWeekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

4.32 kB

Total Files

4

Last publish

Collaborators

  • amekusa