Created
September 30, 2014 10:32
-
-
Save ShMcK/ae8168de755d90d7c1d5 to your computer and use it in GitHub Desktop.
Javascript (ES5) Module Patterns
This file contains hidden or 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
'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