课程: JavaScript: Five Advanced Challenges and Concepts

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Setting up a basic Observer pattern

Setting up a basic Observer pattern

- [Instructor] The easiest way to make sense of the observer pattern is to see one in action. So let's say we have a store that only carries a few products and they rarely have any stock. To get the items from the store, customers can subscribe to the items they want for updates. When the stock of the item is replenished, they get a message letting them know it's available. I have the bare bones for this already set up in the exercise files. We can register a new backpack using the new Product class, and the backpack is called "Green Frog Pack". We can register new customers using the Customer class. Well, I've registered two, Simran and Maiken, and I want to build out the functionality so I can register these two customers as observers of the backpack, so that when the backpack is back in stock, they are notified. That notification happens in two places. Inside the Customer class, we have a method called message…

内容