This topic created in 1371 days ago, the information mentioned may be changed or developed.
const p = new Promise((resolve, reject) => {
console.log(11);
});
console.log(p)
console.log(JSON.stringify(p));
我在谷歌控制台打印的结果是这个
Promise {<pending>}
[[Prototype]]: Promise
[[PromiseState]]: "pending"
[[PromiseResult]]: undefined
但是我具体看的时候就是一个空{}
这些属性到底是在哪里啊原型链里吗
6 replies • 2022-08-12 13:30:42 +08:00
 |
|
1
hangbale Aug 12, 2022
``` DebugPrint: 0x21e0000caa35: [JSPromise] - map: 0x21e0002830b1 <Map[20](HOLEY_ELEMENTS)> [FastProperties] - prototype: 0x21e000249ffd <Object map = 0x21e0002830d9> - elements: 0x21e000002251 <FixedArray[0]> [HOLEY_ELEMENTS] - status: pending - reactions: 0 - has_handler: 0 - handled_hint: 0 - is_silent: 0 - properties: 0x21e000002251 <FixedArray[0]> - All own properties (excluding elements): {} 0x21e0002830b1: [Map] - type: JS_PROMISE_TYPE - instance size: 20 - inobject properties: 0 - elements kind: HOLEY_ELEMENTS - unused property fields: 0 - enum length: invalid - stable_map - back pointer: 0x21e0000023d9 <undefined> - prototype_validity cell: 0x21e0001c4461 <Cell value= 1> - instance descriptors (own) #0: 0x21e0000021e5 <Other heap object (STRONG_DESCRIPTOR_ARRAY_TYPE)> - prototype: 0x21e000249ffd <Object map = 0x21e0002830d9> - constructor: 0x21e000249ea1 <JSFunction Promise (sfi = 0x21e0001df8e5)> - dependent code: 0x21e0000021d9 <Other heap object (WEAK_ARRAY_LIST_TYPE)> - construction counter: 0
```
|
 |
|
2
nitmali Aug 12, 2022 2
chrome 中 console.log 打印出来的是引用的“快照”,点开时会根据引用地址再去获取,就和“快照”不一样了。
|
 |
|
3
tutou Aug 12, 2022
就是 Promise 对象啊,你调用 JSON.stringify 干嘛
|
 |
|
4
zhaol Aug 12, 2022
你打印的时候打开对象没发现后面会有的小的感叹号(好像是 i,不确定了)吗,那个就是告诉你为什么点开看跟不点开看数据不一样的原因。
|
 |
|
5
Danswerme Aug 12, 2022 via iPhone
p 是一个 Promise ,你想拿到数据可以用 p.then(res => console.log(res))
|
 |
|
6
renmu Aug 12, 2022 via Android
因为就是一个 promise ,log 时做了优化
|