All ordinary objects in JavaScript have an internal prototype slot (note: the prototype here does not refer to the prototype property). The ECMAScript standard (http://www.ecma-international.org/ecma-262/6.0/index.html) specifies that this slot is referred to as [[Prototype]]. You could access this slot through the __proto__ property.
__proto__ may not be reliably available across browsers. __proto__ becomes an official property in ECMAScript 6
The prototype property is, however, a property on a constructor function that sets what will become the __proto__ property on the constructed object.
You can access the prototype property of certain types, e.g., the core JavaScript types (Date, Array, and etc). Also a JavaScript function (, which can be regarded as a constructor) has a public prototype property. However, instances of a function do not have a prototype property.
In you case, var b = new x();
, b is an instance of function x. Thus b.prototype is undefined. However, b does have an internal [[Prototype]] slot. If you output b.__proto__
in Google Chrome e.g., version 63.0.3239.132, or Firefox such as version 43.0.4
console.log(b.__proto__);
You will see its [[Prototype]] slot as below:
{log: ƒ, constructor: ƒ}
That's it.
And just for your reference, the whole code snippet is put as below:
var x = function() {
};
x.prototype.log = function() {
console.log("1");
}
var b = new x();
b.log(); // 1
console.log(b.prototype); // undefined
console.log(b.__proto__); // {log: ƒ, constructor: ƒ}
console.log(x.prototype); // {log: ƒ, constructor: ƒ}