Created
January 9, 2017 16:19
-
-
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
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
// 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