Posted By

kayue on 03/03/09


Tagged

pattern


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

LeeRJohnson
Bolek


Module Pattern by Douglas Crockford


 / Published in: JavaScript
 

  1. var singleton = function () {
  2. var privateVariable = 0;
  3.  
  4. function privateFunction(x) {
  5. //detail...
  6. }
  7.  
  8. return {
  9. firstMethod: function (a) {
  10. return a;
  11. },
  12. secondMethod: function (a, b) {
  13. return a+b;
  14. },
  15. thirdMethod: function () {
  16. return privateVariable;
  17. }
  18. };
  19. }();
  20.  
  21. alert(singleton.secondMethod(1,2)); //return 3

Report this snippet  

You need to login to post a comment.