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);
obj
is an instance of which class in this case?ClassOne
a super class forClassTwo
andClassThree
or only forClassTwo
?- And accordingly
ClassThree
is a subclass of onlyClassTwo
or andClassOne
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);
- Does
newObj
become an instance ofobj
?
Help me to understand.