Last active
          July 10, 2023 04:54 
        
      - 
      
- 
        Save guilhermepontes/4504159 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
    
  
  
    
  | const Application = ((d) => { | |
| const privateVariable = 'Private content' | |
| const __private = { | |
| cache: () => { | |
| this.link = d.querySelector('.link') | |
| }, | |
| bind: () => { | |
| this.link.addEventListener('click', this.showContent, false) | |
| }, | |
| showContent: () => console.log(privateVariable) | |
| } | |
| return { | |
| init: () => { | |
| __private.showContent() | |
| __private.cache() | |
| __private.bind() | |
| } | |
| } | |
| })(document) | |
| Application.init() | |
| console.log(privateVariable) //undefined | 
  
    
      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
    
  
  
    
  | var Application = (function(w, d){ | |
| var myPrivateVariable = "My private content"; | |
| var __private = { | |
| cache: function(){ | |
| this.link = d.querySelector('.link-item'); | |
| } | |
| bind: function(){ | |
| this.link.addEventListener('click', this.handleClick, false); | |
| }, | |
| handleClick: function(){ | |
| console.log(myPrivateVariable); | |
| } | |
| }; | |
| return { | |
| init: function(){ | |
| console.log(myPrivateVariable); | |
| __private.cache(); | |
| __private.bind(); | |
| } | |
| }; | |
| })(window, document); | |
| Application.init(); //init the app | |
| console.log(myPrivateVariable); // undefined | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
@albiere makes sense. Updated! :)