javascript - jQuery 库代码

标签 javascript jquery oop dom

为了学习 JS OOP,我正在查看 jQuery 的源代码,以更好地理解它们是如何做事的。我的问题可能看起来很简单,但我无法理解 jQuery 在其库顶部定义的几个变量背后的推理。代码如下所示。

(function( window, undefined ) {

// Use the correct document accordingly with window argument (sandbox)
var document = window.document,
    navigator = window.navigator,
    location = window.location;

....rest of code

What I don't understand is why they created variables for the document, navigator, and location objects.  Does this resolve some type of browser bug?  I don't understand the benefit of doing this.

最佳答案

他们这样做是为了,如果其他脚本错误地(或故意)创建了名为 documentnavigatorlocation 的变量>,它们不会影响 jQuery 对这些变量的使用。

关于javascript - jQuery 库代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11238582/

相关文章:

javascript - 在 Javascript 中构造对象后立即调用对象方法

javascript - 使用 Parse 并尝试在 JavaScript 中解析数据库条目

c++:没有强制转换的包含对象的确切类型

c++ - 面向对象 : how to create a function "addFruit" to add fruit into a vector<fruit>

java - 员工薪资计算

javascript - d3折线图显示不正确

javascript - Bootstrap datetimepicker 获取时间

jquery - 使用 Jquery 添加/删除类事件在 Firefox 中仅触发一次 CSS3 动画

javascript - 更改时的 JQuery 复选框

javascript - 透明文本区域中的光标