Created
January 13, 2015 16:58
-
-
Save tuliofaria/e1755abead5101412ddb to your computer and use it in GitHub Desktop.
Modules
This file contains hidden or 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
| 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(); |
This file contains hidden or 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
| console.log("Este é um modulo."); | |
| module.exports = { | |
| count: 0, | |
| escreva: function(){ | |
| console.log("Escreveu ", this.count++); | |
| } | |
| }; |
This file contains hidden or 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
| // 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