If I can use obj.constructor.prototype to access object prototype
You cannot at all. See how this approach works:
var proto = MyConstructor.prototype; // has an (nonenumberable) property "constructor" proto.hasOwnProperty("constructor"); // `true` // that points [back] to proto.constructor; // `function MyConstructor() {β¦}`
As you can see, this is a circular structure of properties. When you do
var o = new MyConstructor(); // and access o.constructor; // `function MyConstructor() {β¦}` // then it yields the value that is inherited from `proto` // as `o` doesn't have that property itself: o.hasOwnProperty("constructor"); // `false`
But this only works for an object of type o , which inherits the constructor property from its prototype object and where it has useful value with something pointing to the prototype object. Think about
var o = {}; o.constructor = {prototype: o};
Unfortunately. Access to o.constructor.prototype gives here o , and that could be any other meaningless value. The structure is actually the same as above with MyConstructor.prototype - and if you refer to proto.constructor.prototype.constructor.prototype[.constructor.prototypeβ¦] , you will get nothing but proto .
then why can't I use obj.constructor.prototype.constructor.prototype to move the prototype chain and should use Object.getPrototypeOf ?
Since you ended up in a circular structure like MyConstructor.prototype ), this constructor property is not inherited from Object.prototype . To really get the next object in a genuine prototype chain, you must use Object.getPrototypeOf .
var o = new MyConstructor(); console.log(o.constructor.prototype)
Actually it should be MyConstructor.prototype . Sometimes the Chrome console gets confused when displaying useful headers for unnamed objects, but is not always correct.
If you get your prototype, it should give Object.prototype , and when you get the prototype of the MyConstructor function MyConstructor , it should be Function.prototype . Note that you can do the latter using MyConstructor.constructor.prototype again ...