// 聖杯模式 // 為了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();