JS —— 圣杯模式(原型链继承)


        //  圣杯模式
        //  为了son继承father原型上的东西,还可以修改自己原型上的东西,对father原型不影响。
        function inherit(Target,Origin){ 
            function F (){};// 函数F作为一个中间层,上连father,下连Son,使两函数互不干扰
            F.prototype = Origin.prototype;
            Target.prototype = new F();
            Target.prototype.constuctor = Target;
            // son原型归位
            Target.prototype.uber = Origin.prototype;
        }
        Father.prototype.lastName = "Deng";
        function Father(){}
        function Son(){}
        inherit(Son,Father);
        // 运行函数,形参实参相统一
        var son = new Son();
        var father = new Father();

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM