這里需要只需來可能有些API上是andSelf,因為就Query的api是這樣寫的,andSelf現(xiàn)在是.addBack()的一個別名。在jQuery1.8和更高版本中應(yīng)使用.addBack()
源碼其實也是這樣的
jQuery.fn.andSelf = jQuery.fn.addBack
源碼其實也是這樣的
jQuery.fn.andSelf = jQuery.fn.addBack
2014-12-16
jQuery內(nèi)部使用了,具體
pushStack: function(elems) {
var ret = jQuery.merge(this.constructor(), elems);
ret.prevObject = this;
ret.context = this.context;
return ret;
},
this.constructor() 指向了jQuery類
pushStack: function(elems) {
var ret = jQuery.merge(this.constructor(), elems);
ret.prevObject = this;
ret.context = this.context;
return ret;
},
this.constructor() 指向了jQuery類
2014-12-15
我是模擬的代碼,這個是模擬jquery的機制,如果要完整的實現(xiàn),代碼量相當(dāng)?shù)拇蟮?。選擇器sizzle就有2000多行
2014-12-15
jQuery就是這樣實現(xiàn)的,其實原理很簡單,無非就是保存了上一次的引用,
_$ = window.$;
window.$ = _$;
就是一個交換的原理,如果調(diào)用了noConflict方法,就把之前保存的_$覆蓋當(dāng)前的$
要特別注意的事,必須在加載jQuery之前已經(jīng)存在一個$命名空間的庫,否則_$ = window.$就沒有意義了
_$ = window.$;
window.$ = _$;
就是一個交換的原理,如果調(diào)用了noConflict方法,就把之前保存的_$覆蓋當(dāng)前的$
要特別注意的事,必須在加載jQuery之前已經(jīng)存在一個$命名空間的庫,否則_$ = window.$就沒有意義了
2014-12-15
原來從集合中從末尾開始倒數(shù)取值是這樣做的哇:
num < 0 ? this[num + this.length] : this[num]
學(xué)習(xí)了
num < 0 ? this[num + this.length] : this[num]
學(xué)習(xí)了
2014-12-15
$$().setName('慕課網(wǎng)-Aaron').getName();或
$$(1).setName('慕課網(wǎng)-Aaron').getName();沒區(qū)別呀?
這樣的話i的初始值是不是該為0
$$(1).setName('慕課網(wǎng)-Aaron').getName();沒區(qū)別呀?
這樣的話i的初始值是不是該為0
2014-12-15
fn是prototype的縮寫,別名。也就是看到的這個:
jQuery.fn = jQuery.prototype = {
init:function(){
return this
}
jQuery.fn = jQuery.prototype = {
init:function(){
return this
}
2014-12-14
首先,右邊最后那段代碼init函數(shù)少傳個selector參數(shù),再者,init函數(shù)里面應(yīng)該返回this吧?
為什么jquery使用init方法就能避免無限遞歸呢?應(yīng)該這樣理解嗎?:
通過init為橋梁返回該對象,避免了new該對象(實際也是在調(diào)用),導(dǎo)致無限遞歸。
簡單的無限遞歸模擬:
function ajQuery = (selector) {
return new ajQuery(selector);
}
為什么jquery使用init方法就能避免無限遞歸呢?應(yīng)該這樣理解嗎?:
通過init為橋梁返回該對象,避免了new該對象(實際也是在調(diào)用),導(dǎo)致無限遞歸。
簡單的無限遞歸模擬:
function ajQuery = (selector) {
return new ajQuery(selector);
}
2014-12-14