這里需要只需來可能有些API上是andSelf,因為就Query的api是這樣寫的,andSelf現在是.addBack()的一個別名。在jQuery1.8和更高版本中應使用.addBack()
源碼其實也是這樣的
jQuery.fn.andSelf = jQuery.fn.addBack
源碼其實也是這樣的
jQuery.fn.andSelf = jQuery.fn.addBack
2014-12-16
jQuery內部使用了,具體
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就是這樣實現的,其實原理很簡單,無非就是保存了上一次的引用,
_$ = window.$;
window.$ = _$;
就是一個交換的原理,如果調用了noConflict方法,就把之前保存的_$覆蓋當前的$
要特別注意的事,必須在加載jQuery之前已經存在一個$命名空間的庫,否則_$ = window.$就沒有意義了
_$ = window.$;
window.$ = _$;
就是一個交換的原理,如果調用了noConflict方法,就把之前保存的_$覆蓋當前的$
要特別注意的事,必須在加載jQuery之前已經存在一個$命名空間的庫,否則_$ = window.$就沒有意義了
2014-12-15
原來從集合中從末尾開始倒數取值是這樣做的哇:
num < 0 ? this[num + this.length] : this[num]
學習了
num < 0 ? this[num + this.length] : this[num]
學習了
2014-12-15
$$().setName('慕課網-Aaron').getName();或
$$(1).setName('慕課網-Aaron').getName();沒區別呀?
這樣的話i的初始值是不是該為0
$$(1).setName('慕課網-Aaron').getName();沒區別呀?
這樣的話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