假设我有一个在窗口OtherWindow
中创建的对象OtherObj
,它与当前的窗口ThisWindow
不同:
const ThisWindow = window;
const ThisObj = ThisWindow.history;
const OtherWindow = window.open();
const OtherObj = OtherWindow.history;
console.log(ThisObj instanceof Object); //true
console.log(OtherObj instanceof Object); //false
console.log(OtherObj instanceof OtherWindow.Object); //true, but this method only if I already have a reference to OtherWindow
现在想象一下,如果我only引用了OtherObj
,有没有办法得到用来创建它的窗口?也许OtherObj
上有一个属性包含对创建它的窗口的引用?
我目前正试图想出一种跨窗口的方法来使用instanceof
操作符.如代码示例所示,如果变量指向在当前窗口外创建的对象,[variable] instanceof Object
将返回false
.
你们中的一些人可能会说只使用OtherObj instanceof OtherWindow.Object
(返回true
),但只有当我已经有了OtherWindow
的引用时,这才有效.我的问题是假设我还没有提到OtherWindow
.
OtherObj
上是否有指向创建它的窗口的属性?