var jQuery = function(global, factory) {
return new jQuery.fn.init();
}
jQuery.fn = jQuery.prototype = {
constructor: jQuery,
init: function() {
this.jquery = 3;
return this;
},
each: function() {
console.log('each');
return this;
}
}
jQuery.fn.init.prototype = jQuery.fn;
// init構(gòu)造函數(shù)
jQuery().each().each()
上面是一段jQuery原始碼,我的問題是為什麼程式碼最後一行的第二個(gè)each
函數(shù)還能夠執(zhí)行
溫故而知新,可以為師矣。 博客:www.ouyangke.com
原型中this指向的是實(shí)例物件,each裡return this來傳回這個(gè)對(duì)象,從而實(shí)現(xiàn)鍊式呼叫