jQuery源码解读三选择器

直接上jQuery源码截取代码函数

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

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

// 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);
},blog

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

init: function (selector, context, rootjQuery) {it

},
}io

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

相关文章
相关标签/搜索