为什么窗口或文件不能被设置为未定义或为空? [英] Why window or document can't be set to undefined or null?

查看:83
本文介绍了为什么窗口或文件不能被设置为未定义或为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但我还没有找到答案。为什么我们不能做到以下几点?

This might be a silly question but I haven't found an answer to it. Why can't we do the following?

window = undefined

document = undefined

我知道这些都是全局和在浏览器中也有,但Javascript的是如何工作的思考,是不是有可能?那些重新评估每一次我们试图访问这些时间呢?

I know those are globals and are available in browsers but thinking of how JavaScript works, is it not possible? Are those re-evaluated every time we try to access them?

我也想知道如何使用窗口文件对象保留它们是什么,甚至将它们设置为后随机值......可能是一个数量未定义

I am also interested in knowing how the window or document objects remain what they are even after setting them to a random value... may be a number or undefined or null.

推荐答案

据的标准

窗口属性必须返回窗口对象的浏览器上下文的 WindowProxy 对象。
  该文件属性必须返回窗口对象的最新文件对象。

The window attribute must return the Window object's browsing context's WindowProxy object. The document attribute must return the Window object's newest Document object.

含义窗口是所有脚本进行评估的背景。如果它是可写的,然后上面会不会把握和执行将不遵循规范,因此不写。结果
出于同样的原因,你可以将属性添加到文件,但你不能忽略它。

Meaning window is the context in which all of your scripts are evaluated. If it was writable then the above wouldn't hold and the implementation wouldn't follow the spec, therefore it isn't writable.
For similar reasons you can add properties to document but you can't override it.

您可以通过查看IDL验证这一点

You can verify this by looking at the IDL:

[Unforgeable] readonly attribute WindowProxy window;
[Unforgeable] readonly attribute Document document;

这篇关于为什么窗口或文件不能被设置为未定义或为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆