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()
The above is a piece of jQuery source code. My question is why the second each
function in the last line of the code can still be executed
溫故而知新,可以為師矣。 博客:www.ouyangke.com
This in the prototype points to the instance object, return this in each to return this object, thereby realizing chain calls
Two eachs have the same effect as one each, and the objects are all jQuery
Because what you are returning is this, let alone two, 10 will do too