Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Promise基础原理
- class P {
- constructor (fn) {
- this.resoleveCbs = []
- this.resoleveFn = () => this.resoleveCbs.forEach(cb => cb())
- fn(this.resoleveFn)
- }
- then (cb) {
- this.resoleveCbs.push(cb)
- }
- }
- console.log('start')
- let p = new P(resolve => {
- setTimeout(() => {
- resolve()
- }, 1000)
- })
- p.then(() => {
- console.log('resolve')
- })
Add Comment
Please, Sign In to add comment