Jquery 源码学习笔记


##1.Jquery 无new创建 —

####jquery的使用方法

$("div").css();
$("#p").attr();

####由此我们发现$()返回的是一个jquery 对象

var jquery = function(){
    var jq = new jquery();
    return jq;
}

####为了解决这样的问题,产生了下面的方法

var jquery = function(){
    return jquery.prototype.init();
}
jquery.prototype = {
    init:function(){
        return this;
    }
}

####为了解决上面的问题,产生了下面的方法

var jquery = function(){
    return new jquery.prototype.init();
}
jquery.prototype = {
    init:function(){
        return this;
    }
}

####为了解决上面问题,于是诞生了这样的方法

var jquery = function(){
    return new jquery.prototype.init();
}
jquery.prototype = {
    init:function(){
        return this;
    }
}
jquery.prototype.init.prototype = jquery.prototype

####用jquery的原型覆盖jquery.prototype.init的原型,这样new出来的就是jquery.prototype对象


##2.jquery 优雅的链式调用 —

####这个就理解起来就简单多了

var jquery = function(){
    return new jquery.prototype.init();
}
jquery.prototype = {
    init:function(){
        return this;
    },
    name:function(){
        return this;
    }
    sexfunction(){

    }

}
jquery().name().sex()

####每次调用完事之后都返回jquery的原型,下次继续使用


##3.插件接口

####jquery.extend() 用于jquery扩展 ####jquery.fn.extend() 用于jquery对象的扩展

####jQuery.extend = jQuery.fn.extend = function() {}

####关键在于this