Why is the init function in jQuery.prototype? I have put it in jQuery\'s closure and it works fine. I did this:
(function( window, undefined ) {
var jQu
We don't know (ask the library maintainers for their design desicions).
But having it available as a public property does allow overwriting or amending the constructor without harming the jQuery
function, and it makes prototypical inheritance possible where you might need to apply the parent constructor on the child instance:
function MyJQuery(selector, context) {
this.init(selector, context, MyJQuery.root); // <==
// or more explicit:
// jQuery.fn.init.call(this, selector, …);
…
}
MyJQuery.fn = MyJQuery.prototype = Object.create(jQuery.fn);
MyJQuery.root = jQuery(document);