0.0.24 • Published 4 years ago

@browndragon/callable v0.0.24

Weekly downloads
4
License
MIT
Repository
github
Last release
4 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

4 years ago

0.0.24

4 years ago

0.0.21

4 years ago

0.0.22

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 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