Skip to content

Instantly share code, notes, and snippets.

@MarcoWorms
Created July 6, 2016 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcoWorms/08e330e155ce36b670af0af402a2ebe6 to your computer and use it in GitHub Desktop.
Save MarcoWorms/08e330e155ce36b670af0af402a2ebe6 to your computer and use it in GitHub Desktop.
Closure 3
function contador () {
var valor = 0
return {
incrementar: function () {
valor += 1
},
getValor: function () {
return valor
}
}
}
//rode as linhas abaixo individualmente no console dessa vez
var umContador = contador()
umContador.getValor() // => 0
umContador.incrementar()
umContador.getValor() // => 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment