-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
笔记 #26
Comments
Promise相关 // promise allSettled 等待 promise 所有的值,无论是resolve 或者是 rejected。
if(!Promise.allSettled) {
Promise.allSettled = function(promises) {
return Promise.all(promises.map(p => Promise.resolve(p).then(value => ({
state: 'fulfilled',
value
}), reason => ({
state: 'rejected',
reason
}))));
};
}
const p1 = new Promise(resolve => setTimeout(() => resolve(1), 2000))
const p2 = new Promise(resolve => setTimeout(() => resolve(2), 1000))
const p3 = new Promise((resolve, reject) => setTimeout(() => reject('error'), 3000))
Promise.allSettled([p1, p2, p3])
.then(console.log) // p.resolve 如果传入 promise 对象的情况:
const p = new Promise((resolve,reject) => setTimeout(() => reject(5), 1000))
// const p = new Promise((resolve,reject) => setTimeout(() => resolve(5), 1000))
const p2 = Promise.resolve(p)
// resolve 如果传的是一个promise, p2的状态将会等待传入的那个promise 决议,
// 如果 p resolve, 则 p2 变成 resolve 状态,否则,变为reject 状态
console.log(p2)// p2 1s 后变为 rejected, value 为5, 同时抛出一个错误。 |
在 Java 或其它面向对象设计模式中,类与类之间主要有 6 种关系,他们分别为:依赖,关联,聚合,组合,继承,实现。他们的耦合度依次增强。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
一些知识的笔记
书: 你不知道的js
The text was updated successfully, but these errors were encountered: