美文网首页
JavaScript原型继承之圣杯模式

JavaScript原型继承之圣杯模式

作者: 臭袜子满天飞 | 来源:发表于2019-07-08 16:11 被阅读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函数运用了函数式变成的思想

    相关文章

      网友评论

          本文标题:JavaScript原型继承之圣杯模式

          本文链接:https://www.haomeiwen.com/subject/mkcahctx.html