instance-callable
v1.0.0
Published
Create classes whose instances are callable
Readme
instance-callable
Create classes whose instances are callable.
Install
pnpm add instance-callableUsage
Extend Callable and override [call].
import { call, Callable } from 'instance-callable'
class Counter extends Callable<[amount: number], number> {
value = 0
override [call](amount: number) {
this.value += amount
return this.value
}
}
const counter = new Counter()
counter(2) // 2
counter(3) // 5
counter.value // 5Function properties
Callable instances are functions. They retain the standard function members:
namelengthprototypecallapplybindargumentscaller
Do not reuse these names for unrelated subclass fields or methods. Own function
properties such as name, length, and prototype can block field assignment.
Inherited methods such as call, apply, and bind can be shadowed and stop
behaving like standard function methods. arguments and caller also have
restricted legacy behavior.
