JS Module Pattern With Constructor

eliminate need to expose special init function for any given module by combining

by kpowz

JavaScript

var module = (function () {
    // private variables and functions
    var foo = 'bar';
    var options = {};
    var defaults = {
      yes: 'yes',
      no: 'no'
    }

    // constructor
    var module = function (opts) {
        console.log(opts);
        console.log(defaults);
        options = opts;
        Object.extend(options, defaults);
    };

    // prototype
    module.prototype = {
        constructor: module,
        something: function () {
            console.log('options : '+ options);
        }
    };

    // return module
    return module;
})();

var my_module = new module({ yes: 'no', no: 'maybe'});

console.log(my_module)
my_module.something();