Why Window Or Document Can't Be Set To Undefined Or Null?
This might be a silly question but I haven't found an answer to it. Why can't we do the following? window = undefined OR document = undefined I know those are globals and are av
Solution 1:
According to the standard:
The window attribute must return the
Window
object's browsing context'sWindowProxy
object. The document attribute must return theWindow
object's newestDocument
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.
You can verify this by looking at the IDL:
[Unforgeable] readonly attribute WindowProxy window;
[Unforgeable] readonly attribute Document document;
Solution 2:
window
is the context. You cant't do this = something
else.
document
is property of window. It is not writable or configurable.
Object.getOwnPropertyDescriptor( window, 'document' );
output
Object {value:document,
writable:false,
enumerable:true,
configurable:false}
Post a Comment for "Why Window Or Document Can't Be Set To Undefined Or Null?"