jQuery和IIFE包装器的说明? [英] Jquery and IIFE wrapper clarification?

查看:50
本文介绍了jQuery和IIFE包装器的说明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不能像在此示例中看到的那样重新定义window:

The window can not be redefined like we see in this example:

http://i.stack.imgur.com/IYX0p.jpg

那么为什么jquery以window开头(甚至使用相同的名称)?

So why jquery starts itself with window ( and it even uses the same name)?

(function( window, undefined ) {...})( window );

我的意思是,它可能在其中使用window ...

I mean , it could have use window inside it...

p.s. undefined技巧与之无关...

p.s. the undefined trick has nothing to do with it...

推荐答案

我认为可能的解释是使JQuery更易于在其他上下文中移植,在该上下文中,全局对象可能未命名为window,甚至没有嵌入到某些对象中.其他脚本,在window引用当前作用域(或激活对象)中的有效令牌的情况下.

I guess a possible explanation is to make JQuery easier to port in other contexts, where the global object may not be named window, or even embedded in some other scripts, in the case window refers to a valid token in the current scope (or in the activation object).

无论如何,我认为这可能有用的唯一原因是因为jQuery代码可以使用window名称而不必担心,因为任何供应商都可以仅通过更改一行而将名称绑定到所需的任何对象. jQuery源(最后一个).

Anyway, the only reason why I think this may be useful is because the jQuery code can use the windowname without worry, because any vendor can bind the name to whatever object it wants, only by changing a single line of the jQuery source (the last one).

这篇关于jQuery和IIFE包装器的说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆