Skip to content

Instantly share code, notes, and snippets.

@deavial
Forked from ShMcK/JavascriptModulePatterns
Created June 3, 2016 03:41
Show Gist options
  • Save deavial/f9f541f468dcd1f6fe091e383548df23 to your computer and use it in GitHub Desktop.
Save deavial/f9f541f468dcd1f6fe091e383548df23 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