我正在检查Promise构造函数的静态方法。当我在控制台记录Promise构造函数属性时,我看到了resolve和reject方法:
console.log(Object.getOwnPropertyNames(Promise))
// Array(7) [ "all", "race", "reject", "resolve", "prototype", "length", "name" ]
我想知道resolve和reject方法是不是在执行器(executor)中作为其参数使用的相同方法,还是它们是单独的不同事物:
const myFirstPromise = new Promise((resolve, reject) => {
// do something asynchronous which eventually calls either:
//
// resolve(someValue); // fulfilled
// or
// reject("failure reason"); // rejected
});
规范提到了 Promise Resolve 函数和 Promise.resolve(x),它是 %Promise_resolve% 内部对象。请问这两者是否相同?