Skip to content Skip to sidebar Skip to footer

Chrome's Javascript Console: What Does It Output In Terms Of Objects?

From the javascript console in Chrome: > function Person(name){this.name=name;} undefined At this point, Person.prototype should be an empty Object according to the Javascript

Solution 1:

No, the prototype always has the constructor property which points to the function it is the prototype of. And of course it inherits from an object too, that is the internal __proto__ property.

It is defined in ECMAScript 5 Section 13.2, Creating Function Objects:

(...)

16. 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.

17. Call the [[DefineOwnProperty]] internal method of proto with arguments "constructor", Property Descriptor {[[Value]]: F, { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}, and false.

18. Call the [[DefineOwnProperty]] internal method of F with arguments "prototype", Property Descriptor {[[Value]]: proto, { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}, and false.

(...)

This means nothing else than:

Create a new empty object called proto (16). Define the property constructor on that object and set the value to F (the function itself) (17). Then define the property prototype on the function F and set its value to proto.


If you alert an object, then the object is converted to a string. The default behaviour is to convert an object to the [object Object] string, unless the "special" toString method is overridden.

The Chrome console lists these properties because it is meant for debugging, so you need information. [object Object] is not very informative.

FWIW, an empty object looks like this:

empty object

You can also see the internal __proto__ property here. An empty object always inherits some default properties, but it does not have own properties.

Solution 2:

Chrome's console is a developer tool. It is meant to show in-depth info. In this case, you're looking at the pre-defined properties of the class you just defined.

Solution 3:

Those are methods and properites inherited from the Object class.

It discusses the defaults here

Post a Comment for "Chrome's Javascript Console: What Does It Output In Terms Of Objects?"