我們有那個使用包裝代碼的基本jQuery
腳本,它使用傳輸的全局參數window
初始化。是否需要傳輸此參數? window
是一個全局參數,如果您轉移或不轉移,您可以從內部函數中使用它。爲什麼傳輸全局窗口參數如果是全局窗口參數
這是什麼原因?
(function (window, undefined) {
var jQuery = (function() {
//Define a local copy of jQuery
var jQuery = function (selector, context) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init(selector, context, rootjQuery);
},
//some code
//...
//...
//...
window.jQuery = window.$ = jQuery;
})(window);
基本上,在非常頻繁的重複中所說的是,擁有一個全局變量可以縮小其名稱。 – 2013-02-14 14:17:04