每日更新-js代码技巧: setTimeout和promise
对比一下setTimeout和Promise的实现方法,promise感觉更高大上。
setTimeout 实现setTimeout(function() { console.log('1s') setTimeout(function() { console.log('2s') }, 1000) }, 1000)Promise 实现
const wait = () => new Promise((resolve, reject) => { setTimeout(resolve, 1000) }) wait().then(() => { console.log('1s') return wait() }) .then(() => console.log('2s'))
- 萌面大虾,每日更新js代码技巧:想要了解更多请关注:https://github.com/57abc/dev
相关推荐
89500297 2020-05-05
sfkong 2020-08-02
delmarks 2020-04-09
gjcxywwx 2019-11-04
前端开发Kingcean 2019-10-22
Magicsoftware 2019-10-19
xuewenke 2012-02-05
jiangbo0 2019-09-08
85403263 2019-07-01
梦秋雨 2019-07-01
87241940 2019-06-30
83251242 2019-06-30
85281643 2019-06-29
whynotgonow 2019-06-29
84563376 2019-06-29