在 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);
谁能解释为什么第二个参数是未定义?
提前致谢!
I noticed that in the jQuery core, one of the two arguments passed in is undefined.
(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);
Can anyone explain why the second argument is undefined?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Undefined 是一种类型,但也是一个全局变量。
您可以通过执行
undefine =whatever
来让模块覆盖 undefined 的值。jQuery 使用立即函数来确定窗口和未定义的范围。
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/undefined
Undefined is a type but is also a global variable.
You can have a module that overwrites the value of undefined by doing
undefined = whatever
.jQuery uses a immediate function to scope window and undefined.
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/undefined
由于有人可以像这样覆盖 undefined ,因此
您的立即函数的代码将按应有的方式传递它(保持未定义)。我认为它在 我从 jQuery 中学到的 10 件事中提到过来源。
Since someone could overwrite undefined like this
Code of your immediate function will pass it as it should be (stay undefined). I think it's mentioned in 10 Things I Learned from the jQuery Source.