I am looking into how jQuery source code works, I understand the jQuery object just forwards a call to jQuery.fn.init
where jQuery.fn
is just a reference to jQuery.prototype
.
Then in the source code, there is this line:
// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;
There is a comment to explain what the code does but I still can't understand it.
Can someone explain what does this line of code means? what later instantiation is it talking about and why do we need to set init's prototype to jquery's prototpe?
is there a reason (like avoiding conflicts or readability or whatever) that jQuery source code is using jQuery.fn instead of using jQuery.prototype directly?