js中为什么不能使用__prototype__调用父类上面的方法呢

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方法呢?  


繁华开满天机
浏览 516回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript