1、继承
1、Student.prototype=Object.create(Person.prototype)
如果student.prototype直接等于Persion.prototype 则会导致修改Student.prototype则Person.prototype也会改变
故 Object.create创建一个原型是Persion.prototype的对象 既继承了其prototype方法 又不影响
2、Student.prototype.constructor=Student
prototype改变则会影响constructor改变 会导致原型链乱序 故强制指回自己
Student.prototype整个修改后 (Student.prototype={}) 对于已经实例化的对象 不改变 对于以后再实例化出来的对象有影响
继承
最新推荐文章于 2020-05-28 17:48:49 发布