Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. // we are prepending “private” variables with an underscore _
  2. var MyExampleModule = function() {
  3.  
  4. var _privateVar = “Hello”;
  5.  
  6. return {
  7. getPrivateVar: function() {
  8. return _privateVar;
  9. },
  10. setPrivateVar: function(value) {
  11. _privateVar = value;
  12. }
  13. }
  14.  
  15. }
  16.  
  17. var myExampleModuleInstance = new MyExampleModule();
  18.  
  19. console.log(myExampleModuleInstance._privateVar); // logs undefined
  20. console.log(myExampleModuleInstance.getPrivateVar()); // logs “Hello”
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement