Class: PrototypeWrapper

PrototypeWrapper()

The Prototype Wrapper will resolve dependencies up in the prototype tree. If you require a module which inherits other prototypes, this wrapper will insert proxies in between the inheritance steps which then will handle the dependency injections in the parent prototypes. You can still call super() with arguments in the constructor, the supplied arguments will then be appended to the injected properties in the constructor of the parent prototype.

Constructor

new PrototypeWrapper()

Author:
  • Wolfgang Felbermeier (@f3lang)
Source:

Methods

buildPrototypeChain(prototype) → {Array}

Will traverse the prototype chain recursively up to the top and convert it to an array.

Parameters:
Name Type Description
prototype Object

The prototype to build a chain for

Source:
Returns:

An array with all prototypes of the chain ordered from bottom to top.

Type
Array

require(module, root, requestId) → {PrototypeWrap}

Will wrap the node require and inject prototype proxies for the dependency injection.

Parameters:
Name Type Description
module String

The path of the module to require

root String

The identifier of the tree to work in

requestId String

The id of the current injection request

Source:
Returns:

An Object containing the resolved prototype and the original chain

Type
PrototypeWrap

restoreOriginalPrototypeChain(originalChain)

After instantiation of the module it is important to restore the original prototype tree, since node will somehow cache it, which will lead to problems when traversing the tree again.

Parameters:
Name Type Description
originalChain Array

The original prototype chain as an Array

Source:

wrapPrototype(prototype, root, requestId) → {Object}

Will wrap a prototype in a proxy, that will inject the dependencies into the original prototype constructor.

Parameters:
Name Type Description
prototype Object

The prototype to wrap

root String

The identifier of the tree to work in

requestId String

The id of the current injection request

Source:
Returns:

The wrapped prototype

Type
Object