Created
July 26, 2016 11:30
-
-
Save tuliofaria/72953c6c4b898561aee5e8d91dd589ab 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
// simple function | |
function funcao(){ | |
console.log("Função"); | |
} | |
funcao(); | |
// self-invoking function | |
// função que já é chamada assim que definida. E cria um escopo separado do global ou de onde ela esta contida. | |
// ideal para isolar e não misturar com o contexto global. | |
(function(){ | |
})(); | |
// self invoking function | |
// sendo atribuída a uma variável | |
var conta = (function(){ | |
var contador = 0; | |
//return function(){ contador++; console.log(contador); } | |
return { | |
contar: function(){ | |
contador++; | |
}, | |
out: function(){ | |
console.log(contador); | |
} | |
} | |
})(); | |
conta.contar(); | |
conta.out(); | |
conta.contar(); | |
conta.out(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment