简体   繁体   English

Console.log()打印Q中的Promise对象的状态和值

[英]Console.log() prints state and value of a promise object in Q

When I try print a promise object from Q, I got the following result. 当我尝试从Q打印promise对象时,得到以下结果。

var Q = require('q');
var defaultPromise = new Q();
console.log('defaultPromise', defaultPromise);

defaultPromise { state: 'fulfilled', value: undefined }

Where do the field state, and value come from, I try to find them through visual studio code, the fields are not there. 字段状态和价值从何而来,我尝试通过Visual Studio代码找到它们,而字段不存在。

A promise must be in one of three states: pending, fulfilled, or rejected. 一个承诺必须处于以下三种状态之一:未决,已实现或被拒绝。

A promise must provide a then method to access its current or eventual value or reason. 一个承诺必须提供一种then方法来访问其当前或最终的价值或原因。

Promises/A+ 承诺/ A +

Q(value) returns a promise that is fulfilled with value. Q(value)返回一个用值实现的承诺。 In your case, undefined. 就您而言,未定义。 Q API Reference Q API参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM