Created
March 28, 2013 23:38
-
-
Save grigio/5267695 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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