// jquery的架构分析
var jQuery = function(selector,context){
return new jQuery.fn.init(selector,context);
}
//
jQuery.fn = jQuery.prototype = {
// 主要写一些内部调用方法
// 类似get、pushStack等等方法
}
// 最核心的方法 extend 方法
jQuery.extend = jQuery.fn.extend = function(){
}
// jquery初始化函数
jQuery.fn.init = function(selector,context){
// 解析 selector
// 1.处理非法的selector
// 2. 判断字符串(‘tagName‘,‘#id‘,‘.class‘,‘$()对象‘)
}
// 通过这个
// 直接用jquery.fn(jquery.prototype) 替换jquery.fn.init.prototype
// 这样写的好处是:为了解决既能隔离作用域,同时还能使用jquery原型对象上面的作用域,还能
// 返回实例中访问jquery的原型对象。
// 如果没有这句话,会导致new 的init 中的this 和 jquery 类中的this 分离开来。、
jQuery.fn.init.prototype = jquery.fn;
// jQuery扩展方法
jQuery.extend({
})
// 扩展fn身上的方法
jquery.fn.extend({
})
// 后面的所有扩展方法 都只需要针对于 jquery.extend 和 jquery.fn.extend 进行扩展方法就可以了。
jQuery.extend({
test:function(){
}
})
// 扩展fn身上的方法
jquery.fn.extend({
fnTest:function(){
}
})
// 对于调用test 方法 $.test();
// 对于调用fnTest 方法 $(‘#b‘).fnTest();
原文:http://my.oschina.net/bosscheng/blog/500693