在jQuery核心源代码中传递未定义的参数
我注意到在jQuery核心中,传入的两个参数之一是未定义的。
(function( window, undefined ) { // Use the correct document accordingly with window argument (sandbox) var document = window.document; var jQuery = (function() { // ...defintion of the rest of the core... window.jQuery = window.$ = jQuery; })(window);
谁能解释为什么第二个参数未定义 ?
提前致谢!
Undefined是一种类型,但也是一个全局变量。
您可以通过执行undefined = whatever
来覆盖未定义值的模块。
jQuery使用立即函数来定位窗口和未定义。
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/undefined
因为有人可以像这样覆盖undefined
undefined = true;
您的直接函数的代码将按原样传递(保持未定义)。 我认为它是从jQuery Source中学到的10件事中提到的。