如果不使用 Promise 对象的 then 方法,是否不可能从 Promise 对象中获取 [[PromiseValue]] ? [英] Is it impossible to get the [[PromiseValue]] from a Promise object without using the Promise object's then method?

查看:95
本文介绍了如果不使用 Promise 对象的 then 方法,是否不可能从 Promise 对象中获取 [[PromiseValue]] ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题旨在成为一个规范的问题/答案;请参阅什么是规范问题/答案,其目的是什么?.没有明确的答案,在这里.代替先前已被问及并回答的问题,我将问题张贴在此处.如果该问题已被回答,将删除当前问题.

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 方法,它注册回调以接收承诺的最终价值或承诺不能成为的原因完成.

A promise represents the eventual result of an asynchronous operation. The primary way of interacting with a promise is through its then method, which registers callbacks to receive either a promise’s eventual value or the reason why the promise cannot be fulfilled.

对此问题的评论Promise 的返回值 OP 询问

是的,但这并没有从承诺中取出价值,或者应该我承认这在浏览器中是不可能的?

Right, but does not that take the value out of the promise, or should I accept that this is impossible from the browser?

回复的内容

不愿说明什么是不可能".

Hesitant to state what is "impossible".

随后提供了规范的链接,承诺你错过了承诺点.

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" 时才有意义.

The value with which the promise has been fulfilled or rejected, if any. Only meaningful if [[PromiseState]] is not "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]] ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆