0.0.24 • Published 4 years ago
@browndragon/callable v0.0.24
@browndragon/callable
Install with $ npm i @browndragon/callable.
Why Callable?
It's a base class which is typeof(instance) == 'function', instances can be apply & bind & called, and which nonetheless is declared like a class. An intended use:
// src/example.test.js
import { test, expect } from '@jest/globals';
import Callable from './callable';
test('CallableExample', () => {
class IncreaseBy extends Callable {
constructor(x) {
super((y) => this.x + y);
this.x = x;
}
}
let increasor = new IncreaseBy(1);
expect(increasor(2)).toBe(3);
increasor.x = 5;
expect(increasor(3)).toBe(8);
})Note that while you can use function methods on this instance, this will still be bound to the class instance. This is similar to lambdas; I really recommend making the call to super a lambda for that reason.
Your subclasses can absolutely have additional methods.
0.0.23
5 years ago
0.0.24
4 years ago
0.0.21
5 years ago
0.0.22
5 years ago
0.0.20
5 years ago
0.0.19
5 years ago
0.0.18
5 years ago
0.0.17
5 years ago
0.0.16
5 years ago
0.0.15
5 years ago
0.0.14
5 years ago
0.0.13
5 years ago
0.0.12
5 years ago
0.0.10
5 years ago
0.0.11
5 years ago
0.0.9
5 years ago
0.0.8
5 years ago
0.0.7
5 years ago