-
寫法3: (function(window, undefined) { var jQuery = function() {} // ... window.jQuery = window.$ = jQuery; })(window); 從上面的代碼可看出,自動初始化這個函數(shù),讓其只構(gòu)建一次。詳細說一下這種寫法的優(yōu)勢: 1、window和undefined都是為了減少變量查找所經(jīng)過的scope作用域。當window通過傳遞給閉包內(nèi)部之后,在閉包內(nèi)部使用它的時候,可以把它當成一個局部變量,顯然比原先在window scope下查找的時候要快一些。 2、undefined也是同樣的道理,其實這個undefined并不是JavaScript數(shù)據(jù)類型的undefined,而是一個普普通通的變量名。只是因為沒給它傳遞值,它的值就是undefined,undefined并不是JavaScript的保留字查看全部
-
jQuery一共13個模塊,從2.1版開始jQuery支持通過AMD模塊劃分,jQuery在最開始發(fā)布的1.0版本是很簡單的,只有CSS選擇符、事件處理和AJAX交互3大塊。其發(fā)展過程中,有幾次重要的變革: ? 1.2.3 版發(fā)布,引入數(shù)據(jù)緩存,解決循環(huán)引用與大數(shù)據(jù)保存的問題 ? 1.3 版發(fā)布,它使用了全新的選擇符引擎Sizzle,在各個瀏覽器下全面超越其他同類型JavaScript框架的查詢速度,程序庫的性能也因此有了極大提升 ? 1.5 版發(fā)布,新增延緩對像(Deferred Objects),并用deferred重寫了Ajax模塊 ? 1.7 版發(fā)布,抽象出回調(diào)對象,提供了強大的的方式來管理回調(diào)函數(shù)列表。查看全部
-
其中會用到的正則: //分組 var rcomma = /^[\x20\t\r\n\f]*,[\x20\t\r\n\f]*/; //關(guān)系符 var rcombinators = /^[\x20\t\r\n\f]*([>+~]|[\x20\t\r\n\f])[\x20\t\r\n\f]*/; //空白 var whitespace = "[\\x20\\t\\r\\n\\f]";查看全部
-
Then done查看全部
-
Deffered查看全部
-
Deffere查看全部
-
DOM文檔加載步驟: 1.解析HTML結(jié)構(gòu) 2.加載外部腳本和樣式表文件 3.解析并執(zhí)行腳本代碼 4.構(gòu)造HTML DOM模型 5.加載圖片等外部文件 6.頁面加載完畢查看全部
-
end()和addBack()都是對堆棧的操作,end()的方法是返回上一個執(zhí)行上下文的范圍,而addBack()是將當前選擇的上下文全部push進這個堆棧中,組成一個數(shù)組對象,pushStack的實現(xiàn) pushStack: function( elems ) { // 創(chuàng)建一個新的jquery匹配元素集合 var ret = jQuery.merge(this.constructor(), elems); //把舊對象放進這個堆棧中 ret.prevObject = this; ret.context = this.context; return ret; }查看全部
-
需要調(diào)用鏈式的使用方法。=> 在這個原型方法最后添加 return this;查看全部
-
var jQuery = function(selector, context){<br> return new jQuery.prototype.init(selctor, context);<br> }<br> <br> jQuery.prototype = { init: function() { } } //因為new的實例是指向這個構(gòu)造函數(shù)的原型的 //當我們外面在使用init出來的構(gòu)造函數(shù)的時候,其this是指向jQuery.prototype.init.prototype這個構(gòu)造函數(shù)上的, //這時候我們想要繼續(xù)使用this調(diào)用jQuery上的靜態(tài)方法的時候就需要將jQuery.prototype 上的方法傳遞給init.prototype jQuery.prototype.init.prototype = jQuery.prototype;查看全部
-
function show(data) { $("body").append('<li>' + data + '</li>') } (function(window){ //自自行函數(shù) show('wuhaihua'); })(window) $(function(){//jquery 對象調(diào)用的函數(shù) show('wuhaihua2'); }); $(document).ready(function(){}); $//代表是jquery語言 $(document).ready( function(){ //html document加載完成后執(zhí)行這個函數(shù) show('wuhaihua3'); } ); //jquery() 9種調(diào)用方式==== $() 1.jQuery([selector,[context]]) 2.jquery(element) 3.jquery(elementArray) 4.jquery(object) 5.jQuery(jquery object) 6.jquery(html,[ownerDocument]) 7.jQuery(html,[attributes]) 8.jquery() 9.jquery(callback)查看全部
-
jquery.js prototype.js //如果$的引用是prototype實現(xiàn)的 if( prototype$ ) { //jquery執(zhí)行的代碼 var window._$ = $; //使用了jquery的noConflict //舊引用的$被保存到jquery的初始化中 if( window.$ === jQuery ) { window.$ = _$; } }查看全部
-
為了只讓aQuery值實例一次,所以我構(gòu)造了一個在aquery上的init方法,然后將aQuery構(gòu)造一次,然后將所有的方法全都放在init的原型上去,在把init原型的方法直接賦值給aQuery的原型上去,這樣aQuery只需要構(gòu)造一次,就有了各種調(diào)用的方法,返回的就是init構(gòu)造方法。查看全部
-
工廠模式-創(chuàng)建一個工廠,然后需要什么零件或者方法的時候,就去new這個方法,需要什么調(diào)用什么,工廠中已經(jīng)把所有需要的方法都已經(jīng)實現(xiàn)。<br> var CarFactory = (function() { var Car = function(model, size, year) { this.model = model; this.size = size; this.year = year; }; return function(model, size, year) { return new Car(model, size, year); } ])(); var a = new CarFactory("Tom", 14, 2016); 簡易理解版: var product = {}; product.createProductA = function() { }; product.createProductB = function() { }; product.factory = function(type) { return new product[type]; } product.factory("createProductA");查看全部
-
這里沒怎么看懂查看全部
舉報
0/150
提交
取消