• 2019-06-18 今日头条面试题。 合理设计这两个类。 2。 student 继承person 3 不能使用class


    //1。 合理设计这两个类。 2。 student 继承person  3 不能使用class
    
    
    function Person(id, name) {
        if(!(this instanceof Person)){
            return new Person(id,name);
        }
        this.id = id;
        this.name = name;
    }
    
    
    Person.prototype.say = function (text) {
        console.log("say:" + text)
    };
    
    
    function Student(id, name) {
        if(!(this instanceof Student)){
            return new Student(id,name);
        }
        Person.call(this, id, name)
    }
    
    Student.prototype = new Person();
    Student.prototype.learn = function () {
        console.log('learn')
    };
    
    
    
    
    var s = new Student(111, 'tom');
    var s2 = Student(111, 'tom');   // 支持不使用new关键字创建对象。
    
    
    s.say("hello");
    console.log(s instanceof Person);
    console.log(s instanceof Student);
    

      

  • 相关阅读:
    路由策略
    ospf 路由汇总
    OSPF type1 2
    ospf
    TCP 六种标识位
    raid 10 与 01
    SNMP协议
    ffmpeg剪切视频
    ubuntu18安装sbt
    服务器Ubuntu18重启后宝塔访问不了
  • 原文地址:https://www.cnblogs.com/lhp2012/p/11047076.html
Copyright © 2020-2023  润新知