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();  
  • 相关阅读:
    前端工程化之动态数据代理
    webapp开发之需要知道的css细节
    html-webpack-plugin详解
    file-loader引起的html-webpack-plugin坑
    浅谈react受控组件与非受控组件
    React创建组件的三种方式及其区别
    react项目开发中遇到的问题
    css伪元素:before和:after用法详解
    python之文件操作
    python之range和xrange
  • 原文地址:https://www.cnblogs.com/xiaotaiyang/p/6085354.html
Copyright © 2011-2022 走看看