Skip to content

Instantly share code, notes, and snippets.

@daronwolff
Created January 9, 2017 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daronwolff/c42fe9cc34261a0a6b6a784ab5012983 to your computer and use it in GitHub Desktop.
Save daronwolff/c42fe9cc34261a0a6b6a784ab5012983 to your computer and use it in GitHub Desktop.
This Javascript module design patternsis used for keeping particular pieces of code independent of other components
// Module Design Pattern
var Car = (function() {
var manufacturer = "hyundai";
var wheels = 4;
var price = 149000;
var isAdmin = false;
var loginAdmin = function(u, p) {
if (u === 'admin' && p === '123') {
isAdmin = true;
console.log('Welcome admin');
} else {
console.error('Acces denied');
}
};
var logoutAdmin = function() {
isAdmin = false;
};
var privateInfo = function() {
if (isAdmin) {
console.log("Price " + price.toLocaleString());
} else {
console.error('You are not logged');
}
}
var publicInfo = function() {
return "Manufacturer " + manufacturer + " wheels " + wheels;
};
return {
publicInfo: publicInfo,
loginAdmin: loginAdmin,
logoutAdmin: logoutAdmin,
privateInfo: privateInfo
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment