You-dont-know-js: Async & Performance Chapter 3 "Thenable Duck Typing" section

Created on 20 May 2018  路  2Comments  路  Source: getify/You-Dont-Know-JS

Mainly, you can receive a Promise value from another browser window (iframe, etc.), which would have its own Promise different from the one in the current window/frame, and that check would fail to identify the Promise instance.

Above paragraph consists confusing mentioning of transfer a Promise between browser windows. But if it is about postMessage method, it is seems to be impossible to transfer Promise object. (or even callback function) Would you please kindly illustrate with code sample what is it about?

Most helpful comment

Take a page and put an iframe in it. Inside the iframe, create a promise, then set it into a variable in the parent frame, using a reference like window.top or something like that, to get to the parent window.

Then, check that copied promise with val instanceof Promise, and it'll fail. Because the two "windows" have a separate copy of Promise.

All 2 comments

Take a page and put an iframe in it. Inside the iframe, create a promise, then set it into a variable in the parent frame, using a reference like window.top or something like that, to get to the parent window.

Then, check that copied promise with val instanceof Promise, and it'll fail. Because the two "windows" have a separate copy of Promise.

Thanks for prompt reply!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

psxcode picture psxcode  路  4Comments

IanVS picture IanVS  路  6Comments

vineetpanwar picture vineetpanwar  路  3Comments

aszx87410 picture aszx87410  路  3Comments

G2Jose picture G2Jose  路  4Comments