Skip to content

Instantly share code, notes, and snippets.

@rezoner
Created January 28, 2015 08:50
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 rezoner/ae7d050a3fc122a37e48 to your computer and use it in GitHub Desktop.
Save rezoner/ae7d050a3fc122a37e48 to your computer and use it in GitHub Desktop.
function NamedOne(first, last) {
this.firstName = first;
this.lastName = last;
};
NamedOne.prototype = {
constructor: NamedOne,
get fullName () {
return this.firstName + ' ' + this.lastName;
},
set fullName (value) {
var splittedString = value.split(' ');
if (splittedString.length === 2) {
this.firstName = splittedString[0];
this.lastName = splittedString[1];
}
}
};
x = new NamedOne('John', 'Cat');
x.firstName; //John
x.fullName; //Juan Cat
x.firstName = 'Micaela'; //Micaela
x.fullName; //Micaela Cat
x.fullName = 'Amanda Dog';
x.firstName; // Amanda
x.lastName; // Dog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment