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();  
  • 相关阅读:
    linux命令及相关配置
    EditPlus配置ftp连接linux
    06_事件机制
    HTTP协议简介
    Codeforces Round #691 (Div. 2) C. Row GCD (数学)
    Codeforces Round #690 (Div. 3) E2. Close Tuples (hard version) (数学,组合数)
    牛客编程巅峰赛S2第10场
    Codeforces Round #665 (Div. 2) D. Maximum Distributed Tree (dfs计数,树)
    牛客编程巅峰赛S2第7场
    Codeforces Global Round 12 D. Rating Compression (思维,双指针)
  • 原文地址:https://www.cnblogs.com/xiaotaiyang/p/6085354.html
Copyright © 2011-2022 走看看