Created
January 10, 2012 12:24
-
-
Save wescleymatos/1588783 to your computer and use it in GitHub Desktop.
Orientação a objetos em javascript
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 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