继承

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function People(name){
            this.name=name;
        }
        People.prototype.showName=function(){
            console.log(this.name);
        }
        function Student(){

        }
        Student.prototype=new People("zhangsan");
        Student.prototype.study=function(){
            console.log("学习");
        }
        var stu=new Student();
        // stu.study();
        // stu.showName();
        // Student.prototype
        //原型链的继承
        //原型链的最终指向是object 原型链的终止是null
        // console.dir(stu.__proto__===Student.prototype)
        // console.dir(Student.prototype.__proto__===People.prototype)
        // console.dir(stu.__proto__.__proto__===People.prototype)
        // console.dir(stu.__proto__.__proto__.__proto__)
        console.log(typeof stu.__proto__.__proto__.__proto__)
        //原型
        //Student.prototype
        //People.prototype
        //Object.prototype
        //null
    </script>
</head>
<body>
   
</body>
</html>

 

posted @ 2021-11-17 20:42  与神明画过押  阅读(19)  评论(0)    收藏  举报