Created
January 13, 2015 13:50
-
-
Save tuliofaria/0ad0c6d20c43d7271c4d to your computer and use it in GitHub Desktop.
Exemplo de closure
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
function umaClosure(name){ | |
var x = 0; | |
// metodos privados | |
function contar(){ | |
console.log("Contei "+name," ", x++); | |
} | |
// metodos publicos | |
return { | |
cont: contar | |
} | |
} | |
var c = umaClosure("Closure 1"); | |
c.cont(); | |
c.cont(); | |
var c2 = umaClosure("Closure 2"); | |
c2.cont(); | |
c2.cont(); | |
//umaClosure(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment