记录JavaScript原型链

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>原型链</title>
    <script>
        // 1. es5 构造函数
        function Star(uname, uage) {
            this.uname = uname;
            this.uage = uage;
        }
        // 字面量
        Star.prototype = {
            constructor: Star,
            read: function() {
                console.log('can to read!');
                return 'test';
            },
            speak: function() {
                console.log('go to speak');
            },
        };

        var zzh = new Star('zzh', '37');
        console.log(zzh.uname);
        zzh.read();
        // console.log(zzh.__proto__);
        console.log(zzh.__proto__ === Star.prototype); //  对象原型 __proto__
        // console.log(Star.prototype); //  Star的原型对象prototype , 共享方法
        console.log(Star.prototype); //  有一个 对象原型 __proto__ 指向Object
        console.log(Star.prototype.__proto__); // Object 原型对象
        console.log(Star.prototype.__proto__.constructor);
        console.log(Star.prototype.__proto__.constructor.prototype);
        console.log(Star.prototype.__proto__.__proto__); //Object原型对象指向null
    </script>
</head>

<body>

</body>

</html>

 

结果图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值