1.0.5 • Published 5 years ago

@kingjs/polymorphisms v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

@kingjs/polymorphisms

Declared on functions, provides an object declaring symbols for polymorphisms of the function's instances.

Usage

Publish the fact that FooBar implements IFoo and IBar like this:

var polymorphismsId = require('@kingjs/polymorphisms');
var identityId = require('@kingjs/identity');

function IFoo() { }
IFoo.prototype = null;
var IFooId = IFoo[identityId] = Symbol('IFoo')
IFoo.foo = Symbol('foo');

function IBar() { }
IBar.prototype = null;
var IBarId = IBar[identityId] = Symbol('IBar')
IBar.bar = Symbol('bar');

function FooBar() { }
FooBar.prototype[IFoo.foo] = 'foo';
FooBar.prototype[IBar.bar] = 'bar';
FooBar[polymorphismsId] = {
  [IFoo[identityId]]: IFoo,
  [IBar[identityId]]: IBar,
}

var isIFoo = IFooId in FooBar[polymorphismsId]; // true
var isIBar = IBarId in FooBar[polymorphismsId]; // true

See Also

Install

With npm installed, run

$ npm install @kingjs/polymorphisms

License

MIT

Analytics