npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

lazycon

v0.0.3

Published

chain together lazy constructors

Downloads

17

Readme

lazycon

(c)Bumblehead, 2014 MIT-license

Overview:

Construct prototypes and constructors in a lazy style. Chain prototypes and constructors together.

There's a lot of jargon here around constructors and 'lazy', so a use-case example is going to be more helpful here.

A Crockford-style Super Constructor (if you don't construct objects this way you may not want this script):

var myproto = {
    prop1 : 'prop1',
    meth1 : function () {
        console.log(this.prop1);
    }
};

var myconstructor = function (opts) {
    var that = Object.create(myproto);
    that.prop1 = opts.prop1;
    return that;
};

var myobj = myconstructor({ prop1 : 'myprop1' });

myobj.meth1(); // myprop1

When building something big I needed two things:

  1. Lazy definition (then caching) of prototype and constructor.

    lazycon lets you define prototypes and constructor functions dynamically. Expensive definitions are deferred until needed and the result is cached.

  2. The ability to chain prototypes and constructors

    lazycon lets you join multiple prototype and constructor definitions to return a new constructor. Why?:

    augmented prototype objects. You might have a collection of 'views' scripts. Each view inherits methods from one prototype for content, container and error rendering. Other views need prototype methods unique to their function -a view managing a form or one that manages a form control.

    A simple approach defines all view properties on one prototype or uses a deep inheritance chain to build more specific prototypes (slower property lookup).

    lazycon creates one prototype from multiple objects with one layer of inheritence. The cached result is passed to the constructor.

    augmented constructor methods. An augmented prototype object needs an augmented constructor to avoid repeated property definitions in each constructor.

    lazycon passes the constructed object through multiple constructors. Define a prototype and a constructor in one place, then create a new constructor and use corresponding parts from a predefined constructor.


GET STARTED:

  1. Build a constructor

    // static
    var constructor1 = lazycon().defProtoFn({
        propertya : '',
        property1 : '',
        method1 : function () {
            return this.property1;
        }
    }).defConstructFn(function (me, arg1, arg2) {
        me.propertya = 'propa';
        me.property1 = 'thisproperty1';
        me.arg1 = arg1;
        return me;
    });    
        
    // or dynamic
    var constructor1 = lazycon().defProtoFn(function () {
        return {
            propertya : '',            
            property1 : '',
            method1 : function () {
                return this.property1;
            }
        };
    }).defConstructFn(function (me, arg1) {
        me.propertya = 'propa';
        me.property1 = 'thisproperty1';
        me.arg1 = arg1;
        return me;
    });    
  2. Build an inheriting constructor

    var constructor2 = lazycon(
        constructor1
    ).defProtoFn({
        arg2 : '',
        property2 : '',
        method2 : function () {
            return this.property2;
        }
    }).defConstructFn(function (me, arg1, arg2) {
       me.propertya = 'propartyb';
       me.property2 = 'thisproperty2';
       me.arg2 = arg2;
       return me;
    });
  3. Use the constructor

    var constructedobj = constructor2.getNew('arg1', 'arg2');
    console.log(constructedobj.propertya); // propertyb
    console.log(constructedobj.arg1);      // arg1
    console.log(constructedobj.method1()); // thisproperty1
    console.log(constructedobj.method2()); // thisproperty2

Other things...

The constructor function must return the first parameter.

The object is constructed in an obvious way -prototype properties are mapped to an object in a first-in sequential order. Constructors are applied to the result in a first-in sequential order.

A new constructor may inherit from multiple lazycon constructors and will use their cached prototype definitions.

var newconstructor = lazycon(
    constructor1,
    constructor2,
    constructor3
);

Install:

lazycon may be downloaded directly or installed through npm.

  • npm
$ npm install lazycon
  • Direct Download
$ git clone https://github.com/iambumblehead/lazycon.git

Test:

to run tests, use npm test from a shell.

$ npm test

License:

scrounge

(The MIT License)

Copyright (c) 2014 Bumblehead [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.