JS高级----------------->原型最终指向了哪里

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    function Person(age) {
        this.age = age;
    }
    Person.prototype.eat = function () {
      console.log("Person的吃")
    };
    var per = new Person(10);
    console.dir(per);
    console.dir(Person);
    /*
    *实例对象中有__proto__原型
    *构造函数中有prototype原型对象
    * prototype也是个对象所以也有__proto__原型
    * 实例对象中的__proto__指向的是构造函数的原型对象
    * 所以prototype中的__proto__指向的某个构造函数的prototype原型
    *
    * */
    //Person中的prototype中的__proto__的指向
    console.log(Person.prototype.__proto__);//Object
    //实例对象per中的__proto__指向的是Person中的prototype,
    // Person中的prototype中的__proto__指向的是Object中的prototype,
    // Object中的prototype中的__proto__指向的是null
</script>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/cuilichao/p/9572660.html