美文网首页
js中方法继承

js中方法继承

作者: _Enco_ | 来源:发表于2017-08-15 11:49 被阅读0次
    function Teacher(name,age){
          Person.call(this,name,age);
        }
        function Person(name,age){
          this.name = name;
          this.age = age;
        }
        Person.prototype.getName = function(){
          console.log(this.name);
        }
        Teacher.prototype = Person.prototype;
        Teacher1.prototype.constructor = Person;
        //Teacher.prototype = new Person();
        var t = new Teacher('enco',18);
        console.log(t.name);
      //console.log(Person.prototype);
      //console.log(t.prototype);
        t.getName()
    

    call 和 apply

    相关文章

      网友评论

          本文标题:js中方法继承

          本文链接:https://www.haomeiwen.com/subject/tevmrxtx.html