Each function can be called as a constructor (with the new keyword).
function Dog() { this.legs = 4; }
When you call it as a regular function, var dog = Dog() , it will define window.legs in browsers as 4 (something a little different, but related if in Node.JS), and set dog to undefined .
However, if you call it a constructor like var dog = new Dog() , it will create a new object and set its constructor to this function and assign this new dog object. It will install its internal prototype (which in some browsers can be accessed as dog.__proto__ ) to the prototype constructor ( Dog.prototype ). Or, in pseudo code,
var dog = { legs: 4 }; dog.constructor = Dog; dog.__proto__ = Dog.prototype;
Thus, dog.constructor.prototype not, strictly speaking, the prototype of dog , it is an object that will be assigned to the prototype when the constructor function is launched. And, in particular, Dog.prototype not a prototype of the dog function (only the prototype that its instances will acquire). The reason prototype not available for non-functions, because non-functions cannot be used as constructors, so it makes no sense to have it (since its only function should be copied to the constructed objects of the __proto__ instance).
The object in your example still has a prototype but is not directly accessible; you can either go the hacker route in browsers that allow it ( a.__proto__ ), or request a browser ( Object.getPrototypeOf(a) ).
source share