js 继承

js如何实现继承

(通过对象冒充来实现的继承)
<script>
        function Stu(name,age){
            this.name = name;
            this.age = age;
            this.show = function () {
                window.alert("公共类")
            }
        }
        //实现继承(通过对象冒充来实现的继承)
        function MidStu(name,age){
            this.stu = Stu;
            this.stu(name,age);//这句必须写,js是通过对象冒充来实现的继承(因为js是动态语言,如果不执行,则不能实现继承效果)
        }
        var midStu = new MidStu("xxc","22");
        midStu.show();
    </script>

 

posted on 2018-11-20 20:35  xxcxxc  阅读(202)  评论(0编辑  收藏  举报