Skip to content

Instantly share code, notes, and snippets.

@tuliofaria
Created January 13, 2015 16:58
Show Gist options
  • Save tuliofaria/e1755abead5101412ddb to your computer and use it in GitHub Desktop.
Save tuliofaria/e1755abead5101412ddb to your computer and use it in GitHub Desktop.
Modules
var modulo1 = require('./modulo1');
modulo1.escreva();
modulo1.escreva();
modulo1.escreva();
var modulo2 = require('./modulo2');
var m2 = modulo2("M2");
m2.conta();
m2.conta();
m2.conta();
m2.conta();
var m3 = modulo2("M3");
m3.conta();
m3.conta();
//modulo2.escreva();
//modulo2.escreva();
//modulo2.escreva();
console.log("Este é um modulo.");
module.exports = {
count: 0,
escreva: function(){
console.log("Escreveu ", this.count++);
}
};
// modulo 2
var c = 0;
module.exports = function(name){
var x = 0;
// metodo privado
function contar(){
console.log("Dentro do modulo2 ", name, " > ", x++," > ", c++);
}
// metodos publicos
return {
conta: contar
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment