课程: JavaScript: Five Advanced Challenges and Concepts
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Solution: Temperature display - JavaScript教程
课程: JavaScript: Five Advanced Challenges and Concepts
Solution: Temperature display
(upbeat music) - [Instructor] In the answer code for this challenge you have the starting point for an observer pattern inside the weather station class. And the goal of this challenge is to complete this observer pattern. In the test code, weather station is registered followed by two new weather display instances. Then the weather display instances subscribe to the weather station for updates. And finally a series of temperature changes take place. The goal for the subscribed weather displays is to register the temperature changes anytime there's a change in the weather station. To solve this challenge, we need to add three missing methods to our observer pattern. Those being add observer, remove observer, and notify observer. Before we start, note that in this example, instead of using arrays I'm using a set to register the observers and a map to register the display names. Now there's no particular reason…