html-es6前端

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
    </body>
    <script type="text/javascript">
        // function Star(name,age){
        //     this.name=name;
        //     this.age=age;
        //     this.sing=function(){
        //         console.log('唱歌')
        //     }
        // }
        // let ldh = new Star("刘德华",18);
        // Star.prototype.ids = 99;
        // console.log(ldh.__proto__.ids);
        // console.log(ldh.ids);
        
        // Star.sex = "男";
        // Star.prototype.constructor.sex = "女";
        // ldh.__proto__.constructor.sex = "不男不女";
        // console.log(Star.sex);
        // console.log(Star.prototype.constructor.sex);
        // console.log(ldh.__proto__.constructor.sex);
        // 原型链
        function Star(uname,age){
          this.uname=uname;
          this.age=age;
          this.myFun = function(){
              console.log(33333333);
          }
        }
        Star.prototype={
          constructor: Star,
          sing:function(){
            console.log('唱歌');
          },
          movie:function(){
             console.log('演电影');
          }
        }
        var ldh=new Star('刘德华',18)
        Object.prototype.myFun = function(){
            console.log(1111111111);
        }
        Star.prototype.__proto__.myFun = function(){
            console.log(222222222);
        }
        ldh.show();
        // Star.prototype.__proto__.myFun();
        // ldh.__proto__.__proto__.myFun();
        // Star.myFun();
        // ldh.myFun();
        // 1. 当访问一个对象的属性或方法时,首先查找这个对象自身有没有
        // 2. 如果没有就查找它的原型(也就是 __proto__ 指向的prototype 原型对象 )
        // 3. 如果还没有找到就查找原型对象的原型(Object的原型对象)
        // 4. 依次类推一直找到Object为止( null )
        // 5. __proto__ 对象原型的意义就在于为对象成员查找机制提供一个方向,或者说一条线路 

        // console.log(Star.prototype);
        // Object.prototype.constructor.ids = 100;
        // console.log(Star.prototype.__proto__.constructor.ids);
        // console.log(ldh.__proto__.__proto__.constructor.ids);
        // console.log(ldh.ids);
        
        // Object.prototype.ids = 99;
        // console.log(Star.prototype.__proto__.ids);
        // console.log(ldh.__proto__.__proto__.ids);
        // console.log(Object.prototype.__proto__);
        // console.log(Star.prototype.__proto__.__proto__);
        // Object.prototype.sex = "男";
        // Star.prototype.__proto__.ids = 99;
        // console.log(Object.prototype.ids);
        // console.log(Star.prototype.__proto__.sex);
        // console.log(Object.prototype==Star.prototype.__proto__);
        
        
    </script>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值