首页 > 技术文章 > js原型继承四步曲

songgirl 2017-11-25 17:33 原文

<sctript>

    //1.创建父类

    function Parent(){

        this.name = name;

    }

    Parent.prototype.age = 20;

    //2.创建子类

    function Child(){

    Parent.call(this,"zhangsan");

    }

    //3.确立继承关系

    Child.prototype = Object.create(Parent.prototype);

    //4.改变构造器

    Chils.prototype.constuctor = Child;

</script>

推荐阅读