Advertisement
khangnguyen

module-pattern

Sep 8th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var myModule = (function() {
  2.     // private attr
  3.     var _priVar = 10;  
  4.  
  5.     // private function
  6.     var _priMethod = function() { return "foo"; }  
  7.  
  8.     return {
  9.         // public attr
  10.         pubVar: 10,
  11.         // private function
  12.         pubMethod: function() { return "bar"; },
  13.         // access to private method and variable
  14.     getData: function() { return _priMethod() + _priVar}   
  15.     }
  16. })();   // get the anonymous function to execute and return
  17.  
  18. MyModule.getData();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement