-
-
Save brainwire/e2b3d07fdf0791ced723 to your computer and use it in GitHub Desktop.
Module Design Pattern
This file contains 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
var HTMLChanger = (function() { | |
var contents = 'contents' | |
var changeHTML = function() { | |
var element = document.getElementById('attribute-to-change'); | |
element.innerHTML = contents; | |
} | |
return { | |
callChangeHTML: function() { | |
changeHTML(); | |
console.log(contents); | |
} | |
}; | |
})(); | |
HTMLChanger.callChangeHTML(); // Outputs: 'contents' | |
console.log(HTMLChanger.contents); // undefined |
This file contains 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
var Exposer = (function() { | |
var privateVariable = 10; | |
var privateMethod = function() { | |
console.log('Inside a private method!'); | |
privateVariable++; | |
} | |
var methodToExpose = function() { | |
console.log('This is a method I want to expose!'); | |
} | |
var otherMethodIWantToExpose = function() { | |
privateMethod(); | |
} | |
return { | |
first: methodToExpose, | |
second: otherMethodIWantToExpose | |
}; | |
})(); | |
Exposer.first(); // Output: This is a method I want to expose! | |
Exposer.second(); // Output: Inside a private method! | |
Exposer.methodToExpose; // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment