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>

原文地址:https://www.cnblogs.com/alex-xxc/p/9991391.html