方法1:
function inherit(target,origin){
function F(){}
F.prototype = origin.prototype;
target.prototype = new F();
target.prototype.constructor = target;
target.prototype.uber = origin;
}
function Father(name){this.name}
function Son(){}
Father.prototype.eat = function(){console.log("吃鸡")}
inherit(Son,Father);
var s1 = new Son();
console.log(s1.__proto__)
console.log(s1.uber)
方法2:
var inherit = (function(){
function F(){};
return function(target,origin){
F.prototype = origin.prototype;
target.prototype = new F();
target.prototype.constructor = target;
target.prototype.uber = origin;
}
})();
function Father(name){this.name}
function Son(){}
Father.prototype.eat = function(){console.log("吃鸡")}
inherit(Son,Father);
var s1 = new Son();
console.log(s1)