An accessor method lets a component expose a property while controlling what happens when that property is read or assigned. A getter can return a stored value; a setter can store a value and trigger component behavior. section 3.2 section 5.3
Configure a component with property assignment
A search component can define setters for apiKey and searchTerm that save each value and call doSearch(). From outside, assigning element.searchTerm = 'parrot' looks like setting a variable, but runs the setter. A matching getter can return the stored search term. section 3.2
Listing 3.7. Getters and setters for our component’s configurable options
set apiKey(value) { #1
this._apiKey = value;
this.doSearch();
}
set searchTerm(value) { #2
this._searchTerm = value;
this.doSearch();
}
These setters store each option and start a search, showing how property assignment can initiate component logic. section 3.2
Accessors can also connect JavaScript properties to HTML attributes. In the slider, getters read attribute values and setters update them; an attribute-change callback then refreshes the slider or changes its color. section 3.6












