Documentation


const chain = require('chainchainchain')

Chain objects are expected to evaluate like any other object. However, chain manipulation should be limited to the following methods.

( obj [, obj , ...] ) Create a chain object.
obj object
Objects from which to inherit.
returns chain
Mind that the rightmost objects always become the eldest in chain as this method adds to the top of the chain. If you want to add to the bottom of the chain, use .
.set.owncontext boolean
Bind methods to their corresponding object's context instead of the origin object. Defaults to false.

The origin object is always younger than any chained object.
.set.uniqueness
Deprecated.
.set.allowloops boolean
Allow for inheritance loops when chaining chain objects. Defaults to false.
.set.setchained boolean
Allow values to be assigned on all objects in chain with the declared property key. Defaults to false.
Mind that if the chain doesn't have the property, an error is thrown.
add ( ch , obj ) Add objects to the top of the chain.
ch chain
Target chain.
obj object/array
Object or array of objects to add to the top of the chain.
returns array
Mind that the rightmost objects always become the eldest in chain as this method adds to the top of the chain. If you want to add to the bottom of the chain, use .
Returns an array of objects in chain.
pre ( ch , obj ) Add objects to the bottom of the chain.
ch chain
Target chain.
obj object/array
Object or array of objects to add to the bottom of the chain.
returns array
Mind that the leftmost objects always become the youngest in chain as this method adds to the bottom of the chain. If you want to add to the top of the chain, use .
Returns an array of objects in chain.
rep ( ch , x , o ) Replace object in chain.
ch chain
Target chain.
x object
Object to replace from chain.
o object
Object to replace x with.
returns array
Mind that this method replaces all instances of x in the chain.
Returns an array of objects in chain.
rem ( ch , x ) Remove objects from chain.
ch chain
Target chain.
x object/array
Objects to remove.
returns object
Mind that this method removes all instances of x in the chain.
Returns an array of objects in chain.
pop ( ch ) Remove the eldest chained object.
ch chain
Target chain.
returns object
Returns the removed object, like Array.prototype.pop.
shift ( ch ) Remove the youngest chained object.
ch chain
Target chain.
returns object
Returns the removed object, like Array.prototype.shift.
rol ( ch , n ) Rotate chained objects.
ch chain
Target chain.
n number
Number of rotations. Negative numbers invert the direction of the rotation.
returns array
If n > 0 youngest chained objects rotate to the eldest position.
If n < 0 eldest objects rotate to the youngest chained position.
Returns an array of objects in chain.
is ( z ) Check for a chain object.
z any
Target.
returns boolean
Returns true if z is a chain object.
origin ( ch ) Get origin object.
ch chain
Target chain.
returns object
The origin object is always younger than any chained object.
arr ( ch ) Get all objects in chain.
ch chain
Target chain.
returns array
raw ( ch , prop [, callback] ) Get each object's selected property from chain.
ch chain
Target chain.
prop string
Name of the property or method you want to return.
callback function
Callback function that takes an array of properties in chain as an argument.
returns array
Beware of recursion when creating trees by chaining chain objects.
Returned methods are bound to the origin object's context by default. See .

The origin object is always younger than any chained object.

About me

I am a Portuguese web developer, designer and drummer from the city of Porto. If you have any doubts, suggestions or a will to buy me a beer get in touch. Also check out my portfolio.