Skip to content

Instantly share code, notes, and snippets.

@eallegretta
Last active January 29, 2021 17:05
Show Gist options
  • Save eallegretta/0fc3e0113c1e01380d8f95c9790f8cbc to your computer and use it in GitHub Desktop.
Save eallegretta/0fc3e0113c1e01380d8f95c9790f8cbc to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/cazasot
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
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