Created
March 31, 2011 12:36
-
-
Save InFog/896281 to your computer and use it in GitHub Desktop.
Um exemplo pequeno de OO em JavaScript
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
/** | |
* Objeto Usuario (Classe) | |
*/ | |
Usuario = function(nome, email) { | |
this.nome = nome; | |
this.email = email; | |
}; | |
// Métodos do objeto Usuario | |
Usuario.prototype.pegarNome = function() { | |
return this.nome; | |
}; | |
Usuario.prototype.definirNome = function(novoNome) { | |
this.nome = novoNome; | |
}; | |
/** | |
* Testes 'instanciando' novos objetos à partir do objeto Usuario | |
*/ | |
joao = new Usuario('Joao da Silva', '[email protected]'); | |
document.write(joao.pegarNome()); | |
document.write('<br />') | |
joao.definirNome('Joao de Souza'); | |
document.write(joao.pegarNome()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment