js原型链

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>原型链</title>
</head>
<body>
    <script>
        function Star(name,age) {
            this.name =name;
            this.age =age;
        }
        Star.prototype.sing = function () {
            console.log('我会唱歌')
        }
        var ldh = new Star('马云',18);
        // 1.只有是对象就要__proto__原型,指向原型对象
        console.log( Star.prototype)
        console.log( Star.prototype.__proto__ === Object.prototype)
        // 2. Star原型对象里面的__proto__原型指向的是Object.prototype
        console.log(Object.prototype.__proto__)
        //3.我们  Object.prototype原型对象里面的__proto__原型 指向为null

    </script>
</body>
</html>

运行结果

posted @ 2020-05-05 16:42  前端那点事  阅读(377)  评论(0编辑  收藏  举报