JavaScript原型继承之圣杯模式

2019-07-08  本文已影响0人  臭袜子满天飞

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;

    }

}())

var People = function(name,age){

                this.name = name;

                this.age = age;

}

People.prototype.faceColor = function(color){

                console.log(color)

}

var Person = function(){

}

inherit(Person,People);

// console.log(Person.faceColor('yellow'),Person.name)

// Person.prototype.faceColor('yellow')

var per = new Person();

per.faceColor('red');

inherit函数运用了函数式变成的思想

上一篇下一篇

猜你喜欢

热点阅读