1

Consider following JavaScript object

var planet = {
    id: 1001,
    Name: "Mars",
    faction: {
        factionId: 2,
        notification: function () {
            document.write("Mars notified");
        }
    },
    cities: [
        { locationId: 15, name: "Gladius" },
        { city: "MyPlanet", geo: "universal" }
    ]
}

When trying to read planet.cities in Chrome Debugger windows I see these additional items.

enter image description here

Are these part of JavaScript Runtime engine, and do different browsers handle them differently ?

1 Answer 1

3

Every JavaScript has a prototype object from which it inherits (EcmaScript §4.2.1). This is usually referred to as the "internal [[prototype]] property" (EcmaScript §8.6.2). That FF and Chrome make it public as the non-standard (and deprecated) __proto__ property is implementation-specific.

These additional properties you see are on Object.prototype (EcmaScript §15.2.4, MDN), from which all plain objects - and so your object literals - inherit. Again, the double-underscore-properties are implementation-specific and now deprecated by property descriptors (see Object.defineProperty at MDN).

Sign up to request clarification or add additional context in comments.

1 Comment

@RobG: True, although there is no replacement for assigning to it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.