I have 3 objects, Science, Physics and Mathematics.
I want the last two object (Physics and Mathematics)
to inherit the protoype properties of Science.
Yet I want both Mathematics & Physics to update the inherited properties and define theirs. This is done, but I keep getting undefined when I try to access the Science properties and method via an instance of Physics. What could be wrong with my code.
Just to add to this @opeolluwa , you’re going to get this behaviour out of the box anyway with the class syntax. There’s very little point doing what you’re doing, you’re effectively trying to write your own version of something that already exists in the language.
As an aside: JS doesn’t support multiple inheritance, so what you’re doing is likely to break down extremely quickly. Also you are attempting to model this as if the objects are real world things which will also cause things to break down very quickly
Composition would work much better than inheritance here (“Overall subject can contain a collection of child subjects”, rather than “Overall subject is a parent of child subject”)
The name parameter in physics class overwrites the “name” parameter in the superclass, inherits “difficulty” and returns undefined for stuff because prototypes are inherited unless they are linked like what you did.