js的prototype问题
如果定义一个Person,一个Student,如果让Student继承自Person,那么是不是可以这样写呢:Student.prototype=Person?

解决方案 »

  1.   


    function Person(){};
    Person.propotype={
        //....
    }function Student(){}
    Student.prototype=new Person();这个是简单的继承 或者说是扩展
      

  2.   

    搞不清楚隐形原型链__proto__,是永远弄不明白prototype属性的.Student.prototype=Person;
    表明
    Student.prototype.__proto__ === Function.prototype那么当你
    var s = new Student();
    那么s对象对应的整个链是这样的s.__proto__ === Student.prorotype -> Student.prototype.__proto__ ===  Function.prototype -> Function.prototype.__proto__ === Object.prototype -> Object.prototype.__proto__ === null你瞧,Person.prototype并未在链中,所以Student并未继承了Person