zoukankan      html  css  js  c++  java
  • 对象冒充实现继承,原型链继承方法,以及组合继承模式

    function Person (){
        this.name=“张三”;
        this.run = function(){
            alert( this.name+'在运动' )
        }
    }
    Person.prototype.work = function(){
        alert( this.name+'在工作’ )
    }
    // web类 继承person类 原型链+对象冒充的组合继承模式
    function web(){
        Person.call( this )  //  对象冒充实现继承
    }
    var w = new web()
    web.run() // 会执行  对象继承可以继承构造函数里面的方法  
    web.work() // 不会执行   对象继承可以继承构造函数里面的方法  但是无法继承原型链上面的方法跟属性
     // web.protype = new Person()// 原型链继承方法 缺点 实例化子类的时候无法给父类传参
     
    //  组合继承模式
    function Person (name){
        this.name=name;
        this.run = function(){
            alert( this.name+'在运动' )
        }
    }
    Person.prototype.work = function(){
        alert( this.name+'在工作’ )
    }
    function web(name){
        Person.call(this,name)
    }
    web.protype = new Person()
     
     
    好文要顶 关注我 收藏该文 
  • 相关阅读:
    路由守卫
    this.$nextTick() 的一些理解
    3d饼图
    element ui 可编辑的表格
    vue 路由传参
    vue+element ui 时间格式化
    element ui 选择期 传对象
    数据结构学习第十天
    数据结构学习第九天
    数据结构学习第八天
  • 原文地址:https://www.cnblogs.com/art-poet/p/12880608.html
Copyright © 2011-2022 走看看