Last active
January 29, 2021 17:05
-
-
Save eallegretta/0fc3e0113c1e01380d8f95c9790f8cbc to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/cazasot
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 Persona { | |
constructor(nombre, edad, hobbies, amigos){ | |
this.nombre = nombre; | |
this.edad = edad; | |
this.hobbies = hobbies || []; | |
this.amigos = amigos || []; | |
} | |
addFriend(nombre, edad){ | |
this.amigos.push(new Persona(nombre, edad)); | |
} | |
addHobby(hobby){ | |
this.hobbies.push(hobby); | |
} | |
getFriends(){ | |
return this.amigos; | |
} | |
getHobbies(){ | |
return this.hobbies; | |
} | |
} | |
let personaA = new Persona('Johnny Meloslavo', 33); | |
let personaB = new Persona('Juancho Talarga', 20, ['fulbo', 'tenis'], [personaA]); | |
personaB.addHobby('natacion'); | |
personaB.addFriend('Ramon Valdez', 67); | |
alert(personaB.getHobbies()); | |
alert(JSON.stringify(personaB.getFriends())); | |
alert |
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 Persona { | |
constructor(nombre, edad, hobbies, amigos){ | |
this.nombre = nombre; | |
this.edad = edad; | |
this.hobbies = hobbies || []; | |
this.amigos = amigos || []; | |
} | |
addFriend(nombre, edad){ | |
this.amigos.push(new Persona(nombre, edad)); | |
} | |
addHobby(hobby){ | |
this.hobbies.push(hobby); | |
} | |
getFriends(){ | |
return this.amigos; | |
} | |
getHobbies(){ | |
return this.hobbies; | |
} | |
} | |
let personaA = new Persona('Johnny Meloslavo', 33); | |
let personaB = new Persona('Juancho Talarga', 20, ['fulbo', 'tenis'], [personaA]); | |
personaB.addHobby('natacion'); | |
personaB.addFriend('Ramon Valdez', 67); | |
alert(personaB.getHobbies()); | |
alert(JSON.stringify(personaB.getFriends())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment