Created
August 19, 2013 13:55
-
-
Save bradleykronson/6269391 to your computer and use it in GitHub Desktop.
Module Pattern The module pattern gives us the ability to create private and public methods. For example, in the code below, the variable _index and the method privateMethod are private. increment and getIndex are public.
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 _index = 0; | |
var privateMethod = function() { | |
return _index * 10; | |
} | |
return { | |
increment: function() { | |
_index += 1; | |
}, | |
getIndex: function() { | |
return _index; | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment