Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Ferias = Ferias || {};
- var Cidade = (function() {
- function Cidade(pNome) {
- var _nome = pNome || false;
- this.setNome = function(psNome) {
- _nome = psNome;
- }
- this.getNome = function() {
- return _nome;
- }
- }
- Cidade.prototype.Viajar = function() {
- console.log("Agendar viagem para " + this.getNome());
- };
- return Cidade;
- }) ();
- Ferias.Cidade = Cidade;
- //Consumindo
- var frs = new Ferias.Cidade("AquiPerto"); //Nova instancia
- frs.Viajar(); //Usando o método Viajar()
- frs._nome = "!Deu ruim!"; //Tentando alterar o atributo diretamente
- frs.Viajar(); //Verifica-se que ñ alterou o atributo
- frs.setNome("Inglêses"); //Forma correta de se alterar o atributo
- frs.getNome(); //Verificando se o atributo foi alterado corretamente
- frs.Viajar(); //Verificando novamente a saída do método Viajar()
- //Ficou "bunitu" !!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement