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

前端 未结 3 686
走了就别回头了
走了就别回头了 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 12:02

    The variable var parentVar = inVar; is a local and private variable available only in the Parent() function and visible only to functions defined in the same scope (Parent()).

    I think that best way here would be to modify the Parent class in such way that the parentVar wouldn't be private, but public:

    function Parent(inVar) {
    
        this.parentVar = inVar;
    
    }
    

提交回复
热议问题