JS实现类似 继承功能

版权声明:随意乱写,切勿当真! https://blog.csdn.net/pehao/article/details/79462962


示例中利用 $.extend(true,.,.);的方法, 让Test1.Say方法扩展到Test1上实现集成.

            function Test1() {

                Test1.prototype.Say = function () {

                    alert(1);
                }
            }

            function Test2() {

                Test2.prototype = $.extend(true, Test2.prototype, Test1.prototype);
            }

            var t1 = new Test1();           

            var t2 = new Test2();

            alert(t1.Say === t2.Say)//true;

猜你喜欢

转载自blog.csdn.net/pehao/article/details/79462962