jQuery基础---链式调用

jQuery的理念是写的更少。使得代码简洁,提高了整体的阅读性。其中链式调用起到了不可忽视的作用,那么链式调用是怎么实现的呢?

       //创建一个obj对象
        var obj = function(){
            console.log('只是obj方法');
        };
        //对obj的功能进行拓展
        obj.prototype = {
            sayHello : function(){
                console.log('hello');
                return this;
            },
            sayBye : function(){
                console.log('Bye');
                return this;
            }
        };
        //创建一个新的对象
        var test = new obj;
        //测试链式调用
        test.sayHello().sayBye();

 

posted @ 2015-09-30 15:14  笨·大叔  阅读(187)  评论(0编辑  收藏  举报