Promise.try
小于 1 分钟
Promise.try
注意
该提案已被撤回,并将从下一个主要的 Core-JS 版本中删除。
模块
类型
interface PromiseConstructor {
try<T>(callbackfn: () => T | Promise<T>): Promise<T>;
}
入口点
core-js/proposals/promise-try
core-js(-pure)/full/promise/try
示例
示例:
Promise.try(() => 42).then((it) => console.log(`Promise, resolved as ${it}`));
Promise.try(() => {
throw 42;
}).catch((it) => console.log(`Promise, rejected as ${it}`));