模仿JQ实现函数链式操作

    // 字面量写法
    var obj={};
    obj.a=function(){
        console.log("a");
        return this;
    };
    obj.b=function(){
        console.log("b");
        return this;
    };
    obj.a().b();

    // 原形链写法
    var JQ = function(){};
    JQ.prototype = {
        show:function(){
            console.log("show");
            return this;
        },
        hide:function(){
            console.log("hide");
            return this;
        }
    };
    var jq = new JQ();
    jq.show().hide();

  

posted @ 2018-04-10 21:09  鱿鱼须须  阅读(334)  评论(0编辑  收藏  举报