标签:turn fat tor func targe asc origin bsp type
function inherit(Target, Origin){
var F = function(){};
F.prototype = Origin.prototype;
Target.prototype = new F();
// son.__proto__ --> new F().__proto__ --> Father.__proto__
Target.prototype.constructor = Target;
//构造出的对象, 能找到自己的超类,超级父级 (究竟继承自谁)
Target.prototype.uber = Origin.prototype;
}
inherit(Son,Father);
Father.prototype.name = "zhang";
function Father(){};
function Son(){};
var son = new Son();
var father = new Father();
雅虎将此方法封装到YUI3库
var inherit = (function(){
var F = function(){};
return function(Target, Origin){
F.prototype = Origin.prototype;
Target.prototype = new F();
Target.prototype.constructor = Target;
Target.prototype.uber = Origin.prototype;
}
}());
JavaScript继承圣杯模式
标签:turn fat tor func targe asc origin bsp type
原文地址:https://www.cnblogs.com/Rooney10/p/13022876.html