Created
February 11, 2019 02:13
-
-
Save alejandrolechuga/63dc2069a8345a1fc46ecde83a10cd80 to your computer and use it in GitHub Desktop.
getters and setters
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
/* 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