jQuery源码解读三选择器

直接上jQuery源码截取代码

// Map over jQuery in case of overwrite
_jQuery = window.jQuery,

// Map over the $ in case of overwrite
_$ = window.$,

// Define a local copy of jQuery 可以看出创建了jQuery.fn.init这样的一个函数返回给$,这样就可以使用$实例了
jQuery = function (selector, context) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init(selector, context, rootjQuery);
},

//下面的这两句,使得$实例可以访问jQuery.fn里面的方法
jQuery.fn = jQuery.prototype = {

init: function (selector, context, rootjQuery) {

},
}

// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;

原文地址:https://www.cnblogs.com/zouyanzhi/p/6594407.html