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