jQuery核心技术

立即执行函数 模块化开发

(function(window){
    var jQuery =function(){

    }
    window.jQuery = jQuery
})(window)

jQuery对象继承原型链上的方法

(function(window){
    var jQuery = function(selector,context){
        return new jQuery.fn.init(selector,context);
    }
    jQuery.fn = jQuery.pototype = {
        constructor:jQuery,
        init:function(selector,context){

        }
    }
    jQuery.fn.init.prototype = jQuery.fn = jQuery.prototype;
})(window)

jQuery.fn.entend和jQuery.extend

1.jquery.fn.extend jquery对象身上都有的方法 原型链上添加方法
2.jquery.extend jquery类本身添加方法

链式调用

var s = {
    method1:function(){
        console.log("method1")
        return this;
    }
    method2:function(){
        console.log("method2")
        return this;
    }
}

方法重载

    function addMethod(obj,name,fn){
        var old = obj[name];
        obj[name]= function(){
            console.log(fn.name)
            if(fn.length === arguments.length){
                console.log(111)
                return fn.apply(this,arguments)
            }else{
                console.log(222)
                return old.apply(this,arguments)
            }
        }
    }
    var p ={num: ["zhang","li","wang"]};
    function f1(){
        console.log("方法1")
    }
    function f2(name){
        console.log("方法2")
    }
    function f3(name,age){
        console.log("方法3")
    }

    addMethod(p,"find",f1);
    addMethod(p,"find",f2)
    addMethod(p,"find",f3)
    p.find();
    p.find("wang")
    p.find("wang","li")
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容