my module pattern

sample of my module pattern

by de Montalembert Jonathan

JavaScript

var MyFunkyLib = (function (d, w, undefined) {
    // private/public vars
    var _public = {},
        var2 = 2,
        how = 'Funky';
    _public.instance = instance = this;
    _public.var1 = 1;
    _public.init = function () {
        instance = this;
    }
    // following are almost equal and are private
    privateFunction = function () {
        return 1;
    }
    _public.getHow = function(){
        return how;
    }
    _public.setHow = function(str){
        how = str;
    }
    function otherPrivateFunction() {
        return 1;
    }

    return _public;

})(document, window, undefined);

MyFunkyLib.init();

// inheritence
MyCoolLib = MyFunkyLib;

MyCoolLib.setHow('Cool');


MyFunkyLib.p = function () {
    return this.var1;
}