Posted By

housecor on 04/13/11


Tagged


Versions (?)

Javascript encapsualtion via the module pattern


 / Published in: JavaScript
 

URL: http://www.infoq.com/presentations/JavaScript-Functions

  1. var MODULE = function () {
  2. var privateVar = 4
  3.  
  4. var privateMethod = function(arg) {
  5. //body here.
  6. };
  7.  
  8. return {
  9. publicMethod : function(arg) { //so when you instantiate this module, you get a single method back. Could return a complex object via json instead here though that relies on the private state.
  10. privateMethod(arg);
  11. },
  12. };
  13. }();

Report this snippet  

You need to login to post a comment.