zoukankan      html  css  js  c++  java
  • js实现继承的五种方式

    function Parent(firstname)  
    {  
        this.fname=firstname;  
        this.age=40;  
        this.sayAge=function()  
        {  
            console.log(this.age);  
        }  
    }  
    function Child(firstname)  
    {  
        this.parent=Parent;  
        this.parent(firstname);  
        delete this.parent;  
        this.saySomeThing=function()  
        {  
            console.log(this.fname);  
            this.sayAge();  
        }  
    }  
    var mychild=new  Child("");  
    mychild.saySomeThing();  
    function Parent(firstname)  
    {  
        this.fname=firstname;  
        this.age=40;  
        this.sayAge=function()  
        {  
            console.log(this.age);  
        }  
    }  
    function Child(firstname)  
    {  
      
        this.saySomeThing=function()  
        {  
            console.log(this.fname);  
            this.sayAge();  
        }  
       this.getName=function()  
       {  
           return firstname;  
       }  
      
    }  
    var child=new Child("");  
    Parent.call(child,child.getName());  
    child.saySomeThing();  
    function Parent(firstname)  
    {  
        this.fname=firstname;  
        this.age=40;  
        this.sayAge=function()  
        {  
            console.log(this.age);  
        }  
    }  
    function Child(firstname)  
    {  
      
        this.saySomeThing=function()  
        {  
            console.log(this.fname);  
            this.sayAge();  
        }  
        this.getName=function()  
        {  
            return firstname;  
        }  
      
    }  
    var child=new Child("");  
    Parent.apply(child,[child.getName()]);  
    child.saySomeThing();  
    function Parent()  
    {  
      
        this.sayAge=function()  
        {  
            console.log(this.age);  
        }  
    }  
    function Child(firstname)  
    {  
        this.fname=firstname;  
        this.age=40;  
        this.saySomeThing=function()  
        {  
            console.log(this.fname);  
            this.sayAge();  
        }  
    }  
      
    Child.prototype=new  Parent();  
    var child=new Child("");  
    child.saySomeThing();  
    function Parent()  
    {  
      
        this.sayAge=function()  
        {  
            console.log(this.age);  
        }  
    }  
      
    Parent.prototype.sayParent=function()  
    {  
       alert("this is parentmethod!!!");  
    }  
      
    function Child(firstname)  
    {  
        Parent.call(this);  
        this.fname=firstname;  
        this.age=40;  
        this.saySomeThing=function()  
        {  
            console.log(this.fname);  
            this.sayAge();  
        }  
    }  
      
    Child.prototype=new  Parent();  
    var child=new Child("");  
    child.saySomeThing();  
    child.sayParent();  
  • 相关阅读:
    网页中这 10 种字体的运用方式,不会让人觉得 Low
    如何估算文章阅读时长?
    如何养出一个三十几亿身家的儿子
    2018免费的隐私保护工具
    写一份好的产品说明书
    安装 Ubuntu 19.10 选用 zfs 文件系统
    ESXI常用命令
    Harbor ($docker login) Error saving credentials
    Vue中使用matomo进行访问流量统计的实现
    eslint Cannot read property 'range' of null错误
  • 原文地址:https://www.cnblogs.com/xiaotaiyang/p/6085354.html
Copyright © 2011-2022 走看看