Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Modules should be Immediately-Invoked-Function-Expressions (IIFE) to allow for private scopes
- // return an object instead of a function
- var ChangeAttribute = (function() {
- var content = 'content' // private variable
- var changeHTML = function() {
- var element = document.getElementById('attribute-to-change');
- element.innerHTML = content;
- }
- return { // here begin the magic ^^, when you return function.
- callChangeHTML: function() { // became public variable, but onlly if you call callChangeHTML!
- changeHTML();
- console.log(content);
- }
- };
- })();
- ChangeAttribute.callChangeHTML(); // Outputs: 'content'
- console.log(ChangeAttribute.content); // undefined
Add Comment
Please, Sign In to add comment