Skip to content

Instantly share code, notes, and snippets.

@InFog
Created March 31, 2011 12:36
Show Gist options
  • Save InFog/896281 to your computer and use it in GitHub Desktop.
Save InFog/896281 to your computer and use it in GitHub Desktop.
Um exemplo pequeno de OO em JavaScript
/**
* 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', 'joao@email.com');
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