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 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.
According to the standard:
The window attribute must return the
Windowobject's browsing context'sWindowProxyobject. The document attribute must return theWindowobject's newestDocumentobject.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With