callable-klass

0.0.1 • Public • Published

Allows to create constructor functions ("classes") that returns callable instances.

Install with npm install callable-klass.

Example:

callable = require 'callable-klass'
 
Foo = callable class 
  a: -> 1
  b: -> 2
  callable: -> @a() + @b()
 
# the `callable` function returns a new constructor that delegates to the original one 
# and adds some magic. Foo still works as expected - its `prototype` is set to the original 
# prototype, and the function's properties are still accessible. 
 
foo = new Foo
 
# `foo` also works as expected, `foo.a()` and `foo.b()` works, but you can also call 
# `foo()` directly, which delegates to the `callable` method 
 
foo() # same as foo.callable(), returns 3 

Readme

Keywords

none

Package Sidebar

Install

npm i callable-klass

Weekly Downloads

1

Version

0.0.1

License

WTFPL

Last publish

Collaborators

  • nadav