Skip to content

Instantly share code, notes, and snippets.

@ShMcK
Created September 30, 2014 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ShMcK/ae8168de755d90d7c1d5 to your computer and use it in GitHub Desktop.
Save ShMcK/ae8168de755d90d7c1d5 to your computer and use it in GitHub Desktop.
Javascript (ES5) Module Patterns
'use strict';
// 1. Revealing Module Pattern
var revModule = function (param) {
return {
// public
funk: funk
};
// private
function funk () {
return param;
}
}();
// 2. Revealing Prototype Pattern
var revProto = function () {
// variables
var x = 42;
};
revProto.prototype = function () {
return {
// public
getX: getX
};
// private
function getX(num) {
return num;
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment