[英]Is there any alternative way to access JavaScript globals that have been shadowed or redefined?
For some unknown reason the name URL
in my event handler points to a string value with the current URL of the browser instead of the constructor for an URL object.由于某些未知原因,我的事件处理程序中的名称
URL
指向一个字符串值,其中包含浏览器的当前 URL,而不是 URL 对象的构造函数。 Trying to call it results in the following error:尝试调用它会导致以下错误:
Uncaught TypeError: URL is not a constructor
The string URL does not appear anywhere in the loaded document which leads me to believe that it is not redefined anywhere in my program.字符串 URL 没有出现在加载的文档中的任何地方,这让我相信它没有在我的程序中的任何地方重新定义。 I have not been able to find anything other that would explain why this phenomena occurs.
我还没有找到任何其他可以解释为什么会发生这种现象的东西。
So my question for a workaround is: Is it possible to access these global constructors in any other way?所以我对解决方法的问题是:是否可以以任何其他方式访问这些全局构造函数?
是的,通过名称window
,只要它也没有被遮蔽或重新定义:
let a = new window.URL(location);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.