delegates2
Node method and accessor delegation utilty.
Installation
$ npm install delegates2
Example
var delegator = ; ...delegator method'acceptsLanguages' 'languages' method'is'
API
new Delegate(proto, prop)
Creates a delegator instance used to configure using the prop
on the given
proto
object. (which is usually a prototype).
prop
support multi level string and object.
const obj = request: url: { return this === objrequesturl; } ;const source = response: header: { return this === sourceresponseheader; } ; delegator delegator
Delegate.delegate(proto, target)
Delegates getters, setters, values, and methods from target to proto.
Delegate.auto(proto, target)
Delegates all getters, setters, values, and methods from target to proto.
Delegate#method(name[, targetName])
Allows the given method name
to be accessed on the host.
You can set the targetName
, specitying then method name, default name
.
delegator method'query' 'qs'; obj // true
Delegate#getter(name[, targetName])
Creates a "getter" for the property with the given name
on the delegated
object.
Delegate#setter(name[, targetName])
Creates a "setter" for the property with the given name
on the delegated
object.
Delegate#access(name[, targetName])
Creates an "accessor" (ie: both getter and setter) for the property with the
given name
on the delegated object.
Delegate#fluent(name[, targetName])
A unique type of "accessor" that works for a "fluent" API. When called as a getter, the method returns the expected value. However, if the method is called with a value, it will return itself so it can be chained. For example:
// gettervar q = request; // setter (chainable)request ;
License
MIT