javascript inheritance

后端 未结 5 1902
长情又很酷
长情又很酷 2020-12-05 21:29

I know there is a lot of similar questions are tons of great answers to this. I tried to look at the classical inheritance methods, or those closure methods etc. Somehow I c

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 21:43

    You can manually invoke the parent constructor in the subclass constructor like this:

    CHILDClass = function (basevar) {
      PARENTClass.call(this, basevar);
      // do something;
    };
    

    The trick here is using the call method, which allows you to invoke a method in the context of a different object. See the documentation of call for more details.

提交回复
热议问题