August 2017
Beginner
298 pages
7h 4m
English
We use setters and getters all the time when we create a reference to the DOM element. If we have a reference to the weather custom element, we would simply want to set or get latitude or longitude as follows:
currentLatitude = $weather.lat;$weather.lat = newLatitude;
In this case, we need the widget to update if we set a new latitude or longitude. To do that, add the following setters and getters to your Weather class:
get long() { return this.longitude;}set long(long) { this.longitude = long; this.setWeather();}get lat() { return this.latitude;}set lat(lat) { this.latitude = lat; this.setWeather();}
To test if the setters and getters are working properly, let's remove (or comment) the line where the Weather Widget ...
Read now
Unlock full access