user4143172
user4143172

Reputation:

In JavaScript, what is the default value of a function's prototype property?

In Chrome's JavaScript console:

function placeOrder() {
        return 1;
};
undefined
console.log(placeOrder.prototype);
placeOrder {}

But In IE 11, the default prototype property seems to be an empty object. I wonder what is the object "placeOrder { }" in Chrome? I also tested it in Firefox. In Firefox, the prototype property is "placeOrder { }" too.

In IE 11 console:

function placeOrder() {
        return 1;
};
undefined
console.log(placeOrder.prototype);
undefined
[object Object]{} 

Thanks.

Upvotes: 1

Views: 400

Answers (1)

Oriol
Oriol

Reputation: 288250

It's an object which inherits from Object.prototype and has an own constructor property whose value is the constructor function.

See Creating Function Objects

  1. Let proto be the result of creating a new object as would be constructed by the expression new Object() where Object is the standard built-in constructor with that name.
  2. Call the [[DefineOwnProperty]] internal method of proto with arguments "constructor", Property Descriptor {[[Value]]: F, { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}, and false.
  3. Call the [[DefineOwnProperty]] internal method of F with arguments "prototype", Property Descriptor {[[Value]]: proto, { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}, and false.

Upvotes: 3

Related Questions