关于js继承两种
call bind apply 今天说call()继承属性 和 a = object.create(b) 继承方法
call() 继承属性 :
此处Student 就继承了Person 的 sex 和 age
a = object.create(b) 继承方法:
首先先在Person原型里定义一个方法,cry()
再使用 a = object.create(b) 继承方法 Student.prototype = object.create(Person.prototype)
让Student 的原型等于 Person 的原型
但是此处有一个bug
此处的Student.prototype.constructor 指回的是Person.prototype
所以需要
让他指回的对象是自己
完整代码: