为什么要输入窗口和文档而不是正常访问?
通常,为了加快标识符解析过程的速度,将它们用作局部变量可能会有所帮助(尽管IMO的性能改进可能微不足道)。
在非浏览器环境中,传递全局对象也是一种广泛使用的技术,在该环境中,您
window在全局范围内没有标识符,例如:
(function (global) { //..})(this); // this on the global execution context is// the global object itself为什么未定义的heck被传入?
这样做是因为
undefinedECMAscript 3中的global属性是可变的,这意味着有人可以更改其值来影响您的代码,例如:
undefined = true; // mutable(function (undefined) { alert(typeof undefined); // "undefined", the local identifier})(); // <-- no value passed, undefined by default如果您仔细查看
undefined实际上没有被传递(函数调用中没有参数),那是
undefined不使用property
即可获取值的可靠方法之一
window.undefined。
这个名字
undefined在Javascript并不代表什么特别的,是不是像一个关键字
true,
false等等…,它只是一个标识符。
仅作记录,在ECMAscript 5中,此属性被设为不可写…
将我们正在创建的对象直接附加到窗口是否是一个特别好的主意?
当您在另一个函数范围内时,这是一种用于声明全局属性的常用方法。


![使用(function(window,document,undefined){…})(window,document)有什么好处?[重复] 使用(function(window,document,undefined){…})(window,document)有什么好处?[重复]](http://www.mshxw.com/aiimages/31/464626.png)
