Why is it beneficial to rely on the scope chain alone and avoid explicitly referencing the head object in Javascript?

喜你入骨 提交于 2019-12-04 11:28:59

The interpreter always has to use the scope chain. When you write window.alert() it has to walk its way up the scope chain to find the value of window -- you might have a local variable named window that shadows the one in the head, so it can't assume this is the global object.

If JavaScript had a syntax to explicitly denote the top-level context, that would be faster. But it doesn't.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!