Useify
Useify
is a middleware implementation that extends objects.
Example
// var Useify = require( "Useify" ),// should = require( "should" ); var { thishasInitialised = false; thisvalue = 0;} MyClassprototype { thishasInitialised = true; this;}; MyClassprototype { this;} // `Useify` the class; // Adds the first middleware function.MyClass; // Adds the second middleware function. Note that the first argument is the paramater from the// previous middleware function. The last argument should always be the callback to the next// middleware function.MyClass; // This is a named middleware function. By default, middleware functions are named "all". This// will give you the ability to add multiple middleware injection points.MyClass; // Runs the middleware queue of functions. The last argument of `run` is a callback that is // triggered after the queue is emptied. var myClass = ; myClass;
API
Useify(object)
Add Useify
to an object
object.use([params...], [fn])
Adds a middleware function to the queue. A dynamic amount of params can be passed from the previous middleware function. The callback must be the last paramater. use
is chainable.
object.middleware([params...], [fn])
Runs the queue of middleware functions in the order they were added. A dynamic amount of params can be passed from the previous middleware function. The callback must be the last paramater.