zoukankan      html  css  js  c++  java
  • 对象的继承

    function inherit(p){
        if (p == null) throw TypeError();    //p是一个对象,但不能是null
        if (Object.create)                   //如果Object.create()存在
            return Object.create(p);         //直接使用它
        var t = typeof(p);                   //否则进行进一步检测
        if (t !== "object" && t !== "function") throw TypeError;
        function f() {};                     //定义一个空构造函数
        f.prototype = p;                     //将其原型属性设置为p
        return new f();                      //使用f()创建p的继承对象
    }
    View Code

    参数为需要继承的对象

  • 相关阅读:
    四级英语day9
    123
    像程序员一样思考
    Kali
    OS X
    Effective Java
    DHU ACM OJ
    Ambari
    Hadoop
    Hadoop2
  • 原文地址:https://www.cnblogs.com/scrit/p/4103112.html
Copyright © 2011-2022 走看看