install
npm install singl
singl 1.0.3
singl provides a concise interface for developing singleton objects. the goal of the project is to make your module code more organized and readable. don't worry about decorating prototypes. singl does it for you.
basic usage
*create yourself a module cityboy *
moduleexports = 'my.module' options: {} //this is the constructor! { thisoptions = options; } //your methods here. { console; } ;
now use your module somewhere
var myInstance = myOptions; myInstance; myInstance2 = myOptions; console;
function signature
implementation notes
- singl expects argument
namespace
to be of typestring
. it is required. - singl expects argument
object
to be of typeobject
, ie a plain object. it is also required. - singl accepts an optional 3rd argument,
freeze
, of typebool
, which would freeze the object if the parameter istrue
. - the
object
parameter must have a property calledinit
which is defined as a function. this is the constructor for your class/object/thingy-ma-jig. - singl returns a constructor function which will apply all arguments given to the
init
method, and return the instantiated instance.
license
MIT