function cancel(promise) { const obj = {}; const p = new Promise((resolve, reject) => { obj.resolve = resolve; obj.reject = reject; }); obj.promise = Promise.race([p, promise]); return obj; } // 使用 const testPromise = new Promise((resolve, reject) => { setTimeout(() => { resolve(123); }, 1000); }); const cancelPromise = cancel(testPromise); cancelPromise.promise.then(res => { console.log(res); }); // 取消 cancelPromise.resolve("取消");