Parent and child constructors

if I have a UserForm class:

class UserForm extends View {
    // no constructor
}


and a View class:

class View {
  constructor(parentElement){ this.parentElement = parentElement }
}


Does anyone know why new UserForm('root') causes the UserForm class to inherit the View constructor and set the parentElement variable correctly? Definitely wasn't the behavior I was expecting 🤔

My best guess is that behind the scenes UserForm is creating a new object from the
View
's prototype, and because one isn't present in the UserForm class it inherits it rather than overriding it if it had been explicitly provided - that would also explain why I don't have to call
super
in this case to set View properties? This is all a guess though, it's been a while since I've looked at prototype inheritance, and this seems like a bit of an edge case that's not included often
Was this page helpful?