Created
February 2, 2012 22:30
-
-
Save Diullei/1726208 to your computer and use it in GitHub Desktop.
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
(function(exports){ | |
function Carro(marca){ | |
this.marca = marca; | |
// este é um campo privado. | |
// campos privados precisam ser definidos dentro do construtor da classe. | |
_km = 0; | |
} | |
Carro.prototype.getKm = function(){ | |
return _km; | |
} | |
Carro.prototype.setKm = function(value){ | |
_km = value; | |
} | |
Carro.prototype.andar = function(){ | |
console.log(textoFormatado.call(this)); | |
} | |
function textoFormatado(){ | |
return 'andando a ' + this.getKm() + 'km/h'; | |
} | |
exports.Carro = Carro; | |
})(this); | |
var camaro = new Carro('camaro'); | |
camaro.setKm(3); | |
camaro.andar(); | |
//=> andando a 3km/h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment