Lately I'm trying to get the technical aspects of the prototype chain. Now I have a few questions about object instantiation.
Consider the following code:
var Foo = function(s) {
this._bar = s;
};
var fooInst = new Foo('test');
Now when I examine the created object, then:
Foo.prototype === Function.prototype; // true
fooInst.prototype === ?
fooInst.prototype.prototype === Object.prototype; // true
I'm wondering, what fooInst.prototype
exactly is. In Chromes inspector it seems to be some kind of Foo
with an constructor
property. But all sources I read about prototypes state that fooInst.prototype === Foo.prototype
should be true.
So my question: how exactly does JS handle the prototype chain. What exactly happens when I call new Foo
.
Thanks in advance!
Edit
So I found, that (in Chrome) Object.getPrototypeOf(fooInst) === Foo.prototype;
is true
, but Object.getPrototypeOf(fooInst) === Object.getPrototypeOf(Foo)
is false
. Why that?