-
-
Save rezoner/ae7d050a3fc122a37e48 to your computer and use it in GitHub Desktop.
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
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