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>
  • 相关阅读:
    产生渐变色的view
    新建一个去除storyboard的项目
    绘制波形图
    文件系统扫描的工具类
    如何动态绘制时钟
    Xcode插件管理器Alcatraz的使用
    UITableView的headerView展开缩放动画
    POPSpring动画参数详解
    Java枚举类使用和总结
    Java判断不为空的工具类总结
  • 原文地址:https://www.cnblogs.com/tutao1995/p/8532788.html
Copyright © 2011-2022 走看看