为什么 jQuery 有一个“window=this” 一开始就说这会加快对窗口的引用?
当我打开 jQuery 的源代码时,我发现了这一行。
var
// Will speed up references to window, and allows munging its name.
window = this
这条线路为何以及如何加速?
When I open jQuery's source code I find this line.
var
// Will speed up references to window, and allows munging its name.
window = this
Why and how this line will speed up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
this
==window
)。“window = this;”
只是在该范围内创建一个本地标识符,以便对其的引用不必在本地范围之外“冒泡”来解析。this
==window
)."window = this;"
simply creates a local identifier in that scope so that references to it do not have to "bubble up" outside of the local scope to resolve.与必须解析为 window 对象的
window
相比,this
对于 JavaScript 来说引用起来会更快。this
would be faster for javascript to reference to, as compared towindow
which would have to be resolved to the window object.