我只是偶然忘记在我的实验中删除 console.log(parent)
并且它记录了 Window
。我不知道有全局变量 parent
。它在哪里定义?我使用的是最新的 Chrome。
最佳答案
它在 the HTML specification 中定义, 具体来说 here :
The parent IDL attribute, on getting, must run the following algorithm:
Let windowProxy be this Window object's
WindowProxy
object.If there is no browsing context with windowProxy as its
WindowProxy
object, then return null.Let context be that browsing context.
If context is a child browsing context of another browsing context parent, then return parent's
WindowProxy
object.Otherwise, context must be a top-level browsing context. Return context's
WindowProxy
object.
另见 MDN .
基本上,parent
是窗口的父级(例如,它是一个框架或 iframe),如果它有的话,或者如果没有,则为窗口本身。
关于javascript - Chrome中指向Window对象的 `parent`变量在哪里定义的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52935127/