Why is F.prototype property inconsistent in logs

30 Views Asked by At

So Functions are of type Object and so can have properties. By default, function F will have a name, length and prototype property, and the prototype property will by default be set to an object which has one key "constructor" that points back to the function itself. i.e.

function F() {
  this.foo = "bar";
}

/* default prototype
F.prototype = { constructor: F};
*/

This can be proven by running console.log(Object.getOwnPropertyDescriptors(F.prototype)); which outputs

 {
    constructor: {
        value: [Function: F],
        writable: true,
        enumerable: false,
        configurable: true
    }
 } 

and that F.prototype.constructor == F evaluates to true.

What is confusing is that console.log(F.prototype); will output just an empty object F {}

Similarly console.log(Object.getOwnPropertyDescriptors(F)); will produce the following:

{
length: { value: 0, writable: false, enumerable: false, configurable: true },
  name: {
    value: 'F',
    writable: false,
    enumerable: false,
    configurable: true
  },
  prototype: {
    value: F {},
    writable: true,
    enumerable: false,
    configurable: false
  }
}

Why is it that these return an empty object F {} when i would have expected something like { constructor: [Function: F] }?

0

There are 0 best solutions below