A computed property derives its value when read instead of storing an independent value. Its getter can read other properties, while its setter can update them when an assignment is made. section 8.1.3
Listing 8.6. Defining computed properties
const shogun = {
name: "Yoshiaki",
clan: "Ashikaga",
get fullTitle(){ #A
return this.name + " " + this.clan; #A
}, #A
set fullTitle(value) { #B
const segments = value.split(" "); #B
this.name = segments[0]; #B
this.clan = segments[1]; #B
} #B
};
assert(shogun.name === "Yoshiaki", "Our shogun Yoshiaki"); #C
assert(shogun.clan === "Ashikaga", "Of clan Ashikaga"); #C
assert(shogun.fullTitle === "Yoshiaki Ashikaga", #C
"The full name is now Yoshiaki Ashikaga"); #C
shogun.fullTitle = "Ieyasu Tokugawa"; #D
assert(shogun.name === "Ieyasu", "Our shogun Ieyasu"); #D
assert(shogun.clan === "Tokugawa", "Of clan Tokugawa"); #D
assert(shogun.fullTitle === "Ieyasu Tokugawa", #D
"The full name is now Ieyasu Tokugawa"); #D
The shogun’s fullTitle getter joins name and clan; its setter splits an assigned title and updates those properties. section 8.1.3
A method such as getFullTitle could provide the same value, but a property can make a value dependent on an object’s state clearer to use. section 8.1.3

