1.在父类和子类上面都实现了一个相同的方法,但是想有时候使用父类方法,有时候使用子类方法,代码是这样的function A () { this.name = 'testA' } A.prototype.sayName = function () { console.log('A') } function B () { A.call(this) this.name = 'testB' } B.prototype = Object.create(A.prototype) B.prototype.sayName = function () { console.log('B') } var a = new A() a.sayName() var b = new B() b.sayName() b.__proto__.sayName() //输出B 这为什么输出的不适A 为什么不能使用__proto__ 来调用父类上面的sayName方法呢?
添加回答
举报
0/150
提交
取消