Suppose this code:

function ClassOne() { this.propClassOne = 'hello1'; } function ClassTwo() { ClassOne.apply(this); this.propClassTwo = 'hello2'; } function ClassThree() { ClassTwo.apply(this); this.propClassThree = 'hello3'; } ClassTwo.prototype = Object.create(ClassOne.prototype); ClassTwo.prototype.constructor = ClassTwo; ClassThree.prototype = Object.create(ClassTwo.prototype); ClassThree.prototype.constructor = ClassThree; var obj = new ClassThree(); console.log(typeof obj, obj); var newObj = Object.create(obj); console.log(typeof newObj, newObj); 

  1. obj is an instance of which class in this case?
  2. ClassOne a super class for ClassTwo and ClassThree or only for ClassTwo ?
  3. And accordingly ClassThree is a subclass of only ClassTwo or and ClassOne as well?

In short, explain how to properly call them in relation to each other.

And if we add to the code above:

 var newObj = Object.create(obj); 
  1. Does newObj become an instance of obj ?

Help me to understand.

  • First give the definition: an instance of the class. - Grundy
  • @Grundy how to do this? Not understood. - Topik 4:02 pm
  • You need to decide what you think is an instance of a class. Then all the answers will be trivial. Without this, there may be a bunch of answer choices, depending on what is considered an instance of the class. - Grundy
  • @Grundy and what is accepted in js to be considered a class instance? - Topik pm
  • one
    Considering that there were no classes in ES5, that is obviously nothing :) - Grundy

1 answer 1

  1. ClassThree
  2. ClassOne is a super class for ClassTwo and ClassThree
  3. Right
  4. newObj will not be an instance of obj . They will have common properties from the prototype (common prototype).

I advise the following sources on this topic: