Skip to content

Instantly share code, notes, and snippets.

@grigio
Created March 28, 2013 23:38
Show Gist options
  • Save grigio/5267695 to your computer and use it in GitHub Desktop.
Save grigio/5267695 to your computer and use it in GitHub Desktop.
// Module pattern test
function show(string) {console.log(string);}
function MyMod (){
// constructor
var c = 0;
function priv(){
c = c+1
return c;
}
function sayA(){
return "boom: " + priv();
}
return { // public methods
sayA: sayA
}
}
var here = MyMod();
var there = new MyMod();
show( here.sayA() ); // 1
show( there.sayA() ); // 1
show( here.sayA() ); // 2
show( there.sayA() ); // 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment