Skip to content

Instantly share code, notes, and snippets.

@robertwalsh0
Last active December 16, 2015 07:19
Show Gist options
  • Save robertwalsh0/5397988 to your computer and use it in GitHub Desktop.
Save robertwalsh0/5397988 to your computer and use it in GitHub Desktop.
Module pattern
var MODULE = (function () {
var my = {},
privateVariable = 1;
function privateMethod() {
// ...
}
my.moduleProperty = 1;
my.moduleMethod = function () {
// ...
};
return my;
}());
// On line 14 it returns 'my'
// but in the JS console I can't call my.moduleProperty
// instead I can call MODULE.moduleProperty
// is it weird that I was expecting to see my.moduleProperty?
// I'm assuming that the way this works is that everything I assign
// while inside the module is assigned to 'my'.
// But in the end I can only call them on MODULE. Is that right?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment