Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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