Skip to content

Instantly share code, notes, and snippets.

@tuliofaria
Created January 13, 2015 13:50
Show Gist options
  • Save tuliofaria/0ad0c6d20c43d7271c4d to your computer and use it in GitHub Desktop.
Save tuliofaria/0ad0c6d20c43d7271c4d to your computer and use it in GitHub Desktop.
Exemplo de closure
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