课程: JavaScript: Five Advanced Challenges and Concepts
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Adding advanced functionality - JavaScript教程
课程: JavaScript: Five Advanced Challenges and Concepts
Adding advanced functionality
- [Instructor] To see why this reactive pattern is so popular, let's expand the example by hooking our temperature monitor to a cooling system. With the reactive pattern in place, all we have to do is extend the reactive object with the new cooling system class, add some basic on-off functionality to it, and bind the cooling system controls to the monitor, so when the temperature changes, the cooling system is triggered. Here's how we do that. I'll go down past the temperature monitor, and add in a new class here called cooling system. Extends, reactive object. Inside the cooling system, we'll set up a constructor that receives nothing. It brings in super and then this status, that's the current status of the cooling system and we'll set it to off by default because we want our cooling system to be off when it's not running. Then I need to set up a method to turn the cooling system on and off depending on the current…