0.0.24 • Published 3 years ago

@browndragon/callable v0.0.24

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

@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

3 years ago

0.0.24

3 years ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago