Is there a way to prevent the use of a function by global variables such as a document, window, navigator, and other declared global functions?
No, if ...
The only way this task is possible is that the lexical domain of functions can be changed - that is, the source is somehow modified, for example, wraps it, as shown below.
Imagine:
;(function () { var window = "Hello"
This approach is often used in libraries to create private namespaces, but in these cases, the original source is also available and designed with this in mind. I used this with document before to change the local version of jQuery.
Although with may look promising at first, itโs important to understand that this is just a lexical construct and also does not introduce dynamic variables.
Happy coding.
user166390
source share