官术网_书友最值得收藏!

Refactoring

In the previous section, you created the addNote function, which works well. It starts by creating some static variables, then we fetch any existing notes, we check for duplicates, and if there are none, we push it onto the list, and then we save the data back into the filesystem.

The only problem is that we'll be doing a lot of these steps over and over again for every method. For example, with getAll, the idea is to fetch all of the notes, and send them back to app.js so it can print them to the screen for the user. The first thing we'll to do inside of the getAll statement is have the same code; we'll have our try-catch block to fetch the existing notes.

Now, this is a problem because we'll be repeating code throughout the application. It will be best to break out the fetching of notes and the saving of notes into separate functions that we can call in multiple locations.

主站蜘蛛池模板: 鄂托克前旗| 当雄县| 神农架林区| 遵化市| 定州市| 元阳县| 上虞市| 彰化市| 平阴县| 马公市| 白玉县| 绥滨县| 综艺| 东源县| 旬阳县| 乳山市| 绩溪县| 会宁县| 南汇区| 深泽县| 石家庄市| 东兰县| 承德县| 平南县| 岳普湖县| 莒南县| 连江县| 青岛市| 新余市| 蒲江县| 英德市| 静乐县| 新闻| 泊头市| 车险| 达尔| 罗甸县| 开江县| 惠州市| 莱西市| 兴隆县|