我創建了一些我想從全局命名空間隱藏的自定義對象和函數(包括限制其可訪問性)。jquery - 命名空間和關閉
如果我把它放在document.ready函數中,它會和放在Closure中一樣有效,還是我需要在document.ready聲明中別名jquery引用,以確保我的自定義代碼不在全局名稱空間中?
選項1.普通文檔準備
$(document).ready(function()
//do custom stuff
選項2:裏面的文件準備關閉
$(document).ready(function(){
(function($) {
//do custom stuff
})(jQuery);
方案3:別名文件jQuery的參考準備
jquery(document).ready(function($) {
//do custom stuff
會是什麼是首選嗎?謝謝