I'm trying to understand the mechanics of setting properties on the window
object.
There is this code:
const owner = Object.getPrototypeOf(Object.getPrototypeOf(window))
const desc = Object.getOwnPropertyDescriptor(owner, "experiment");
const allDesc = Object.getOwnPropertyDescriptors(owner);
console.log(experiment);
/// <div id="experiment">Test</div>
console.log(owner);
/// WindowProperties {Symbol(Symbol.toStringTag): 'WindowProperties'}
console.log(desc);
/// {value: div#experiment, writable: true, enumerable: false, configurable: true}
console.log(allDesc);
/// {Symbol(Symbol.toStringTag): {value: 'WindowProperties', writable: false, enumerable: false, configurable: true}}
<div id="experiment">Test</div>
The most interesting thing in this example is that the owner
object does not have any properties, but we can get a descriptor of the specified property from it, but if we want to query all property descriptors, we will not get the descriptors we need. There is a feeling that this is part of some kind of mechanics, but what?
The DOM specification defines the concept of ID and adds only one algorithm:
Use these attribute change steps to update an element’s ID:
If localName is id, namespace is null, and value is null or the empty string, then unset element’s ID.
Otherwise, if localName is id, namespace is null, then set element’s ID to value.
But it doesn't do anything special other than set/unset the unique identifier (ID) for the specified element
Who knows what's wrong? (yes, it would be great to explain how this works from the point of view of specification algorithms)
HTML defines the Window
interface as a LegacyUnenumerableNamedProperties
, which means it supports named properties, and these properties are not enumerable1.
Its supported property names are defined in the named access on the window object section.
1. Unlike Storage
objects for instance, that also support named access properties, but these are enumerable.