1

To check if the constructor is a constructor of an object1 , do :

     object1=new MyConstructor();
     object1 instanceof MyConstructor === true

if MyConstructor inherits from MyParentConstructor :

  object1 instanceof MyParentConstructor === true  

Also, if MyParentConstructor inherits from MyGrandParentConstructor :

  object1 instanceof MyGrandParentConstructor === true  

It is evident that all classes inherits from Object, thus :

  object1 instanceof Object === true  

Now , What is the code of parents method which give us :

   MyConstructor.parents() ===[MyParentConstructor,MyGrandParentConstructor,Object]
  HTMLDivElement.parents() === [HTMLElement,Element,Object]

Note that you can create a class inherited from another class

Community
  • 1
  • 1
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
  • You may be able to traverse the inheritance chain using [*getPrototypeOf*](http://ecma-international.org/ecma-262/5.1/#sec-15.2.3.2) and that Object's *constructor* property until you reach *null* (the ultimate `[[Prototype]]`). That will return the Objects, but not necessarily their "names". – RobG Dec 16 '14 at 06:46
  • 1
    @RobG yep, similar to recursively read `__proto__` property, until get to `null`. – Leo Dec 16 '14 at 06:50

0 Answers0