Created
July 16, 2019 19:22
-
-
Save pedrobritto/e5adc14070fa306f2f764aca5f376ebe to your computer and use it in GitHub Desktop.
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 Pattern | |
// If not an IIFE, it's contents can be read as a string | |
var Exposer = (function () { | |
// Everything here is private | |
var private = 'contents'; | |
// Everything here is public | |
return { | |
public: function() { | |
console.log(private); | |
} | |
} | |
}()); | |
console.log(Exposer.private); | |
Exposer.public(); | |
// Revealing Module Pattern | |
var Exposer = (function () { | |
// Everything here is private | |
var private = 'contents'; | |
var remainPrivate = function() { | |
console.log('This will not be revealed'); | |
} | |
var showThis = function() { | |
console.log('This will be revealed'); | |
} | |
var showThisToo = function() { | |
console.log('This will be revealed as well'); | |
} | |
// Everything here is public | |
return { | |
showThis: showThis, | |
showThisToo: showThisToo | |
} | |
}()); | |
console.log(Exposer.remainPrivate); // Undefined | |
Exposer.showThis(); // 'This will be revealed' | |
Exposer.showThisToo(); // 'This will be revealed as well' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment