Skip to content

Instantly share code, notes, and snippets.

@alejandrolechuga
Created February 11, 2019 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandrolechuga/63dc2069a8345a1fc46ecde83a10cd80 to your computer and use it in GitHub Desktop.
Save alejandrolechuga/63dc2069a8345a1fc46ecde83a10cd80 to your computer and use it in GitHub Desktop.
getters and setters
/* jshint esnext: true */
// getters y setters
var persona = {
name: 'alejandro',
lastname: 'amador',
get fullname() {
return `${this.name} ${this.lastname}`
},
set fullname(fullvalue) {
const arreglo = fullvalue.split(' ');
this.name = arreglo[0];
this.lastname = arreglo[1];
}
};
console.log(persona.fullname);
persona.fullname = 'jose rodriguez';
console.log(persona.fullname);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment