Skip to content

Instantly share code, notes, and snippets.

@wescleymatos
Created January 10, 2012 12:24
Show Gist options
  • Save wescleymatos/1588783 to your computer and use it in GitHub Desktop.
Save wescleymatos/1588783 to your computer and use it in GitHub Desktop.
Orientação a objetos em javascript
function carro(params){
this.velocidadeAtual = 0;
var velocidadeMax = 100;
this.acelerar = function(){
if(this.velocidadeAtual < velocidadeMax){
this.velocidadeAtual += 10;
alert('vroom');
}
}
}
var car = new carro();
alert(car.velocidadeAtual);
car.acelerar();
// herança
function ClassePai() {
this.teste = function(){
alert('teste da classe pai');
}
}
function ClasseFilho() {
}
// agora a parte legal, vamos herdar os métodos da classe pai
ClasseFilho.prototype = new ClassePai();
// testando
var filhote = new ClasseFilho();
filhote.teste();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment