简体   繁体   中英

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. 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. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM