Skip to content

Instantly share code, notes, and snippets.

@jergason
Created October 24, 2011 22:06
Show Gist options
  • Save jergason/1310494 to your computer and use it in GitHub Desktop.
Save jergason/1310494 to your computer and use it in GitHub Desktop.
Wrong way to do objects in JS?
function Test() {
this.hurp = "HURP";
this.durp = "DURP";
}
Test.prototype.publiclyDoStuff = function(foo) {
this.privatelyDoStuff(foo);
}
Test.prototype.privatelyDoStuff(foo) {
return hurp + foo;
}
@iammerrick
Copy link

http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth

    var MODULE = (function () {
    var my = {},
        privateVariable = 1;

    function privateMethod() {
        // ...
    }

    my.moduleProperty = 1;
    my.moduleMethod = function () {
        // ...
    };

    return my;
    }());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment