Skip to content

Instantly share code, notes, and snippets.

@Diullei
Created February 2, 2012 22:30
Show Gist options
  • Save Diullei/1726208 to your computer and use it in GitHub Desktop.
Save Diullei/1726208 to your computer and use it in GitHub Desktop.
(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