I'm new to this, I have a doubt = > My superhero class can do things that has its parent class Person, that's why I can not scream, but how do I do it in reverse, so that a person can have superpowers? All this has nothing to do with get and set no? I understand that the get method stores a property of its OWN CLASS, but what could I do with set here, and how could I do it for a person to have superpowers? Thank you
class Persona{
constructor(nombre, apellido, edad, cm, hijos, celiacos){
this._nombre = nombre;
this._apellido = apellido;
this._edad = edad;
this._cm = cm;
this._hijos = hijos;
this._celiacos = celiacos;
}
get presentacion(){
return 'Hola mi nombre es ' + this._nombre + ' y tengo ' + this._edad + 'años';
}
gritar(volumen = ' a un volumen desconocido'){ // metodo no necesita function
console.log(this._nombre + ' he pegado un grito' + volumen)
}
}
let amigo1 = new Persona('ivan', 'garcia lopez', 33, 185, false, true)
let amigo2 = new Persona('Fran', 'Manrique', 33, 185, false, true)
console.log(amigo1.presentacion);
amigo1.gritar(' a un volumen estratosferico')
amigo2.gritar();
class Superheroe extends Persona{
constructor(nombre, apellidos, edad, altura, celiaco, hijos, poderes){
super(nombre, apellidos, edad, altura, celiaco, hijos);
this._poderes = poderes;
}
relatarPoder(){
console.log('Tengo ' + this._poderes.length + ' poderes y el primero es ' + this._poderes[0]);
}
get misPoderes(){
return this._poderes;
}
}
let poderes = ['volar', 'escupir fuego', 'matar']
let wonderWoman = new Superheroe('encarni', 'garcia', 35, 178, false, false, poderes);
wonderWoman.gritar(); // Puede gritar ya que extiendo persona a mi superheroe
wonderWoman.relatarPoder();
amigo2.relatarPoder(); // AMIGO 2 NO PUEDE TENER PODER