bin/cli.js
function (db, cname) {
    // build arguments function: add <cname> as first argument
    var buildargs = function (args) {
        var result = [cname];
        // args is Object, we need to iterate all fields with numeric key for collecting arguments
        for (var i = 0; args[i]; ++i) {
            result.push(args[i]);
        }

        return result;
    };
    // method names for creating aliases (db.<method>(cname, ...) -> db.cname.<method>(...))
    var mnames = [
        "save", "load", "remove", "find", "findOne", "update", "count",
        "dropCollection", "dropIndexes", "optimizeIndexes",
        "ensureStringIndex", "rebuildStringIndex", "dropStringIndex",
        "ensureIStringIndex", "rebuildIStringIndex", "dropIStringIndex",
        "ensureNumberIndex", "rebuildNumberIndex", "dropNumberIndex",
        "ensureArrayIndex", "rebuildArrayIndex", "dropArrayIndex"
    ];
    // bind method alias
    var mbind = function (mname) {
        return function () {
            return db[mname].apply(db, buildargs(arguments));
        }
    };

    // collection controller impl
    var colctlimpl = {
        inspect : function() {
            return '\u001b[' + 36 + 'm' + "[Collection]" + '\u001b[' + 39 + 'm';
        }
    };

    var mname;
    // wrap methods
    for (var i = 0; i < mnames.length; ++i) {
        mname = mnames[i];
        colctlimpl[mname] = mbind(mname);
        if (helpGetters[mname]) {
            Object.defineProperty(colctlimpl[mname], '_help_', {value : helpGetters[mname](true)});
        }
    }

    return colctlimpl
}
function (db, cname) {
    // build arguments function: add <cname> as first argument
    var buildargs = function (args) {
        var result = [cname];
        // args is Object, we need to iterate all fields with numeric key for collecting arguments
        for (var i = 0; args[i]; ++i) {
            result.push(args[i]);
        }

        return result;
    };
    // method names for creating aliases (db.<method>(cname, ...) -> db.cname.<method>(...))
    var mnames = [
        "save", "load", "remove", "find", "findOne", "update", "count",
        "dropCollection", "dropIndexes", "optimizeIndexes",
        "ensureStringIndex", "rebuildStringIndex", "dropStringIndex",
        "ensureIStringIndex", "rebuildIStringIndex", "dropIStringIndex",
        "ensureNumberIndex", "rebuildNumberIndex", "dropNumberIndex",
        "ensureArrayIndex", "rebuildArrayIndex", "dropArrayIndex"
    ];
    // bind method alias
    var mbind = function (mname) {
        return function () {
            return db[mname].apply(db, buildargs(arguments));
        }
    };

    // collection controller impl
    var colctlimpl = {
        inspect : function() {
            return '\u001b[' + 36 + 'm' + "[Collection]" + '\u001b[' + 39 + 'm';
        }
    };

    var mname;
    // wrap methods
    for (var i = 0; i < mnames.length; ++i) {
        mname = mnames[i];
        colctlimpl[mname] = mbind(mname);
        if (helpGetters[mname]) {
            Object.defineProperty(colctlimpl[mname], '_help_', {value : helpGetters[mname](true)});
        }
    }

    return colctlimpl
}
collection controller (creation function)