Last active
December 16, 2015 07:19
-
-
Save robertwalsh0/5397988 to your computer and use it in GitHub Desktop.
Module pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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