How to call parent class' method from a subclass in JavaScript so that parent's local variables would be accessible?

前端 未结 3 692
走了就别回头了
走了就别回头了 2020-12-21 10:57

I\'m using one of the approaches to class inheritance in JavaScript (as used in the code I\'m modifying), but do not understand how to attach additional functionality for a

3条回答
  •  感动是毒
    2020-12-21 11:39

    No you can't see the parents local variables. You inherit the parents prototype chain, not their local state. In your case you're applying the parent function onto the child object which does not hold the state.

    apply(this,...)
    

    means that you're binding the function to the current value of this. when you call method b from the child object, its then bound to the child, and therefore is not operating within the closure that contains the parents value.

提交回复
热议问题