我正在检查Promise构造函数的静态方法。当我控制台记录Promise构造函数属性时,我看到了resolve和reject方法:
console.log(Object.getOwnPropertyNames(Promise))
// Array(7) [ "all", "race", "reject", "resolve", "prototype", "length", "name" ]
我想知道这些解析和拒绝方法是否与执行程序中作为参数使用的方法相同,或者它们是分开的不同事物:
const myFirstPromise = new Promise((resolve, reject) => {
// do something asynchronous which eventually calls either:
//
// resolve(someValue); // fulfilled
// or
// reject("failure reason"); // rejected
});
规范中提到了Promise Resolve Functions和Promise.resolve(x),后者是%Promise_resolve%内部对象。有人可以告诉我这些是一样的吗?
MMTTMM
慕森王
相关分类