if (err) {
console.log('Error finding files: ' + err)
else {
files.forEach(function (filename fileIndex) {
console.log(filename)
gm(source + filename).size(function (err values) {
if (err) {
console.log('Error identifying file size: ' + err)
else {
console.log(filename + ' : ' + values)
aspect = (values.width / values.height)
widths.forEach(function (width widthIndex) {
height = Math.round(width / aspect)
console.log('resizing ' + filename + 'to ' + height + 'x' + height)
this.resize(width height).write(dest + 'w' + width + '_' + filename function(err) {
if (err) console.log('Error writing file: ' + err)
)
.bind(this))
)
)
)
多个回调函数和 if/else 语句使代码难以理解 。 如果我们添加更多逻辑 , 它在未来可能变得不可维护 。 由于这个问题 , 引入了更新的功能 。 Promise 似乎可以帮助我们编写一个更简洁的程序 。 Async/await 关键字允许我们编写看起来像同步代码的异步代码 。
今天的爱创课堂小编就分享到这里了 , 有想学习前端 , 了解前端更多知识的同学 , 欢迎大家点赞、关注、私信我!!
- 高通骁龙|中国能够生产机械硬盘吗?
- 固态硬盘|PCI-E 4.0新选择,西部数据WD_BLCK SN770固态硬盘体验
- 普华永道|Web3.0经济中NFT的未来
- 玩CFHD为什么那么卡呢?可能是因为你的电脑不是固态硬盘
- 开源软件|Web3能拯救失落的互联网人吗?
- 编程|打造Web3.0基础设施 百度瞄准元宇宙的“人货场”?
- 固态硬盘|速率高达512GBs!PCIe7.0规范发布,但PCIe4.0或仍是主流!
- Python|十年质保、3400MB/S!279元买512GB NVMe高速固态硬盘
- 硬盘|三大PC厂商从游戏本产品线中砍掉机械硬盘!
- 前端开发|Web前端:前端开发人员与后端开发人员,谁最适合你的业务?
