Why does jQuery has a “window=this” at the very begining and say it would speed up references to window?

徘徊边缘 提交于 2019-12-05 20:05:19
  1. javascript functions have lexical scope
  2. jQuery wraps its entire implementation in an anonymous function
  3. when said function begins execution it is executing in the "global" scope (ie 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.

this would be faster for javascript to reference to, as compared to window which would have to be resolved to the window object.

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