zoukankan      html  css  js  c++  java
  • 继承方式

    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    <script>
    /* JSON.stringify(Json名字)获取JSon的内容
    继承:子类从父类获取父类的属性和方法,且子类添加属性或方法,不影响父类。
    第一种:构造函数继承!!!
    第二种:克隆对象继承!!!
    第三种:类式继承 Pchildren.prototype= new Parent()
    第四种:组合式继承(构造+类式)
    第五种:组合式寄生继承(构造+寄生)!!!!!借助新建实例
    function Fn(){};Fn.prototype=Parent.prototype;Pchildren.prototype=new Fn();

    */
    function Parent(name,age){
    this.name=name;
    this.age=age
    }
    Parent.prototype.showName=function(){
    console.log(this.name);
    };
    //构造函数继承
    function Pchildren(name,age,address){
    Parent.call(this,name,age);
    this.address=address
    }
    // Pchildren.prototype=Parent.prototype;//引用类型,改变指针两个原型同时指向一个内存,任意改变一个都会改变对象原型,
    // 不符合继承的条件
    Pchildren.prototype= new Clone(Parent.prototype);
    Pchildren.prototype.showAddress=function(){
    console.log(this.address)
    };
    var f2= new Parent("parent",30);
    var f1= new Pchildren("children",19,"射洪");
    f1.showName();
    f1.showAddress();
    /*Pchildren.prototype=Clone(Parent.prototype);
    //对象的clone 一
    function Clone(obj){
    var newObj={};
    for(var key in obj){
    if(typeof obj[key]!="object"){
    newObj[key]=obj[key];
    }else{
    newObj[key]=Clone(obj[key]);
    }
    }
    return newObj;
    }*/
    // 对象的克隆 二
    function Clone(obj){
    for(var key in obj)
    this[key]=(typeof obj[key]!="object")?obj[key]:new Clone(obj[key])
    }
    </script>
    </body>
    </html>
  • 相关阅读:
    gps示例代码
    UART 串口示例代码
    Linux soft lockup 和 hard lockup
    Linux嵌入式kgdb调试环境搭建
    Linux嵌入式GDB调试环境搭建
    Linux-workqueue讲解
    USB之hub3
    USB之设备插入波形变化2
    我运营公众号这一个月
    从12306帐号泄漏谈用户密码安全
  • 原文地址:https://www.cnblogs.com/tutao1995/p/8532788.html
Copyright © 2011-2022 走看看