问题描述
这个问题旨在成为一个规范的问题/答案;请参阅什么是规范问题/答案,其目的是什么?.没有明确的答案,在这里.代替先前已被问及并回答的问题,我将问题张贴在此处.如果该问题已被回答,将删除当前问题.
This Question is intended to be a canonical Question/Answer; see What is a canonical question/answer, and what is their purpose?. Do not have the definitive Answer, here. In lieu of the Question having previously been asked and answered am posting the Question here. If the Question has already been answered, will delete the present Question.
Promises/A+ 规范2" rel="nofollow noreferrer">point-2 状态
The Promises/A+ specification at point-2 states
promise 表示异步操作的最终结果手术.与 promise 交互的主要方式是通过它的 then
方法,它注册回调以接收承诺的最终价值或承诺不能成为的原因完成.
在对此问题的评论Promise 的返回值 OP 询问
是的,但这并没有从承诺中取出价值,或者应该我承认这在浏览器中是不可能的?
回复的内容
不愿说明什么是不可能".
followed by providing links to the specification, Promises, You're Missing the Point of Promises.
是否不可能从Promise
对象中获取[[PromiseValue]]
,除了在console.log(promiseObject)
,而不使用Promise
对象的then
方法?
Is it impossible to get the [[PromiseValue]]
from a Promise
object, other than viewing the property value of the object at console.log(promiseObject)
, without using the Promise
object's then
method?
推荐答案
在 ES7 中不可行.promise 的值存储在 [[PromiseResult]] 内部槽:
Not possible in ES7. The value of a promise is stored in the [[PromiseResult]] internal slot:
承诺已被履行或拒绝的价值,如果任何.仅当 [[PromiseState]] 不是 "pending"
时才有意义.
该插槽仅在 PerformPromiseThen 中读取抽象操作,仅通过 公开Promise.prototype.then
.
That slot is only read in the PerformPromiseThen abstract operation, which is only exposed via Promise.prototype.then
.
这篇关于如果不使用 Promise 对象的 then 方法,是否不可能从 Promise 对象中获取 [[PromiseValue]] ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!