实现继承的圣杯模式

function inherit(Target, Origin) {
function F() {
}//定义一个构造函数 用来连接
F.prototype = Origin.prototype;// F的 原型 与 要继承的 构造函数的 原型 引用一致
Target.prototype = new F();//这样 Target实例化的对象的__proto__ = F.prototype
Target.prototype.constuctor = Target;// 将Target 原型的 constuctor 修改为自身
Target.prototype.uber = Origin.prototype;//这样 我们可以通过 Target实例化的对象的__proto_.uber 找到 对象真实继承的原型
}
function Father() {
}
Father.prototype.lastName = 'wang';
function Son() {
}
inherit(Son, Father);
console.log(new Father());
console.log(new Son());
版权声明:
作者:东明兄
链接:https://blog.crazyming.com/note/1533/
来源:CrazyMing
文章版权归作者所有,未经允许请勿转载。
THE END
二维码
海报
实现继承的圣杯模式
function inherit(Target, Origin) {
function F() {
}//定义一个构造函数 用来连接
F.prototype = Origin.prototype;// F的 原……


匿名
匿名@匿名
Brannua