今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Singletons in Node
- [Instructor] In the last lesson we solved the problem of creating multiple instances of the logger class throughout our application by creating a singleton class and then exporting that class to make sure that we only use one instance of the logger. Implementing the get instance method in a singleton class is pretty typical for an object oriented programming language. It's just fine to implement the singleton this way within Node JS. It's also nice because it tells other developers that the logger is a singleton. However, there is a easier and more typical solution for singletons in Node JS, and that's simply to export the instance from the Node JS module. So, within our exercise files under chapter two, lesson three, I'm going to come into my logger.js file and just implement the singleton an easier way by removing the class. Or the need to export a single class and now on line 19 where I export this module,…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。