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

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.

主站蜘蛛池模板: 永定县| 佛坪县| 贵南县| 迁安市| 辰溪县| 水城县| 屏边| 丰原市| 合作市| 萨迦县| 台江县| 昔阳县| 东宁县| 杭锦后旗| 太湖县| 五河县| 湘潭县| 凤城市| 南木林县| 黄龙县| 永善县| 宁城县| 信宜市| 沾益县| 镶黄旗| 石狮市| 宁安市| 宝兴县| 大城县| 得荣县| 杭锦后旗| 漯河市| 晋城| 卫辉市| 常州市| 离岛区| 鄂伦春自治旗| 沙湾县| 积石山| 波密县| 岚皋县|