zoukankan      html  css  js  c++  java
  • es5中的组合继承原理

    //父构造函数
            function Father(uname,age){
                //this 指向父构造函数实列
                this.uname = uname;
                this.age = age;
            };
            Father.prototype.money = function(){
                console.log(1000000);
            }



            //子构造函数
            //继承父类方法
            son.prototype = new Father;
            //修改constructor指向问题,使其指向原来的构造函数;
            son.prototype.constructor = Son;



            function Son(uname,age,score){
                //改变this指向,继承父类属性 
                Father.call(this,uname,age);
                this.score = score;
            }
      
      // 属性继承是通过call()调用函数,修改this指向来实现的
      //方法继承时通过中间对于父类的实例化赋值给子类原型来实现的
      
      //注意:不能通过直接把父类原型赋值给子类原型来实现,因为这样子父类原型会指向同一个地址,成为了共享,而不是继承
      //详解如下图;
     
  • 相关阅读:
    跟layout_weight说88,轻松搞定百分比布局
    跟闪退、程序崩溃说88
    程序的需求层次
    开博
    第十章 数组与集合 发牌程序 实例代码
    C#面向对象基础01
    winform form
    html
    C#语言基础02
    C#语言基础01
  • 原文地址:https://www.cnblogs.com/xu3241/p/13265846.html
Copyright © 2011-2022 走看看