This is a hypothetical question, it really doesn't have a practical use, but...
Let's say you were to do:
document.open = null;
How would one restore document.open to its original functionality, is this possible (without user-made temporary storage)? Is document.open stored in another location under a less known name? Thankyou! :)
Overwriting document.open
creates a variable/function named open
directly on the document
object. However, the original function was not on the object itself but its prototype - so you can indeed restore it.
The open
function is from HTMLDocument.prototype
so you can access it using HTMLDocument.prototype.open
.
To call it directly, use .call()
to specify the object to use it on:
HTMLDocument.prototype.open.call(document, ...);
You can also restore document.open
it by simply assigning it:
document.open = HTMLDocument.prototype.open;
However, remember that HTMLDocument
and thus document
are host objects and it's usually a good idea not to mess with them - especially in IE things are likely to go haywire if you do so.
delete document.open;
It's not intuitive, but using the delete keyword on a customized function will restore the original function, at least as long as the prototype hasn't been overwritten.
Example:
> console.log
function log() { [native code] }
> console.log = function() { }
function () { }
> console.log("Hello world");
undefined
> delete console.log;
true
> console.log("Hello world");
Hello world
Works the same way with document.open and other built-in functions.
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