Skip to content

Instantly share code, notes, and snippets.

@evadav
Created April 9, 2019 09:09
Show Gist options
  • Save evadav/27414e28f410262774a247436047dac3 to your computer and use it in GitHub Desktop.
Save evadav/27414e28f410262774a247436047dac3 to your computer and use it in GitHub Desktop.
Definiendo clases en JS
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