Avoid unnecessary promise wrapping. Understand Promise “then”, it acts like ‘map’ on scalar values and ‘flatMap’ on wrapped promises. e.g Promise.resolve(1)
避免不必要的承诺包装。 了解Promise“ then”,它的作用就像在标量值上的“ map”,在包装的Promise上的“ flatMap”。 例如Promise.resolve(1)
.then(a => a * 2) // a = 1 here, acts like map
.then(a => a * 2)// a = 1,就像地图
.then(a => Promise.resolve(a * 2)) // a = 2, acts like flatMap.
.then(a => Promise.resolve(a * 2))// a = 2,作用类似于flatMap。
.then(a => console.log(a)) // a = 4
.then(a => console.log(a))// a = 4
Practice KISS(Keep it simple stupid), DRY(Don’t repeat yourself) and YAGNI(You aint gonna need it). 练习KISS(保持简单愚蠢),DRY(不要重复自己)和YAGNI(您不会需要它)。Keep Patience. It took time to learn things. https://www.norvig.com/21-days.html
保持耐心。 花时间学习东西。 https://www.norvig.com/21-days.html
Read Pragmatic Programmer and Clean Code.
阅读实用程序员和清洁代码 。
翻译自: https://medium.com/@shiningsandy/writing-clean-code-in-js-b8535c108fc4
相关资源:很有趣的javascript编写的代码