Created
April 9, 2019 09:09
-
-
Save evadav/27414e28f410262774a247436047dac3 to your computer and use it in GitHub Desktop.
Definiendo clases en JS
This file contains 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
class Vehicle{ | |
constructor(color, model){ | |
this.color= color; | |
this.model= model; | |
} | |
sayModel(){console.log('My model is &{this.model}'); | |
} | |
sayColor(){console.log('My color is &{this.color}') | |
} | |
}; | |
class Car extends Vehicle{ | |
constructor(color, model,ruedas){ | |
super(color, model); | |
this.ruedas=ruedas }; | |
sayCocheMoto(){ | |
if (this.ruedas== 4) | |
console.log('Soy un coche'); | |
else if(this.ruedas==2) | |
console.log('Soy una moto'); | |
} | |
} | |
class Moto extends Vehicle{ | |
constructor(color, model,ruedas){ | |
super(color,model,ruedas); | |
this.ruedas=ruedas } | |
sayCocheMoto(){ | |
if (this.ruedas== 4) | |
console.log('Soy un coche'); | |
else if(this.ruedas==2) | |
console.log('Soy una moto'); | |
} | |
} | |
let coche = new Car('black', 'diesel',4); | |
console.log (coche.sayCocheMoto()); | |
console.log (vehicle.sayModel() | |
); | |
let moto = new Moto('black','diesel',2); | |
console.log(moto.sayCocheMoto()); | |
console.log(vehicle.sayModel()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment