I\'ve tried to understand ECMAScript 2015 specification in one point: Internal Slots of Objects. But this section appeared very unclear to me, especially this sentence:
It's simply an artifice used to be able to describe precisely how the objects should behave.
They are not real members of the objects and even if in some implementation they are you are not allowed to access them with portable code.
In other words it's a way to write the specification that allows describing behavior with imperative code that is formally more precise that just using a wordy "natural-language" description of what the behavior should be.
Internal slots / methods are pseudo-properties / -methods that the specification uses to define required behavior. ("Abstract operations" are a related mechanism of the spec.) Slots represent state (values), and methods describe algorithms (behavior). They may or may not correspond to properties of objects used by the engine, but they're not available to user code, except as exposed by some part of the public API. The actual implementation an engine uses may be very different from what the internal methods sketch out, but to be compliant they have to produce behavior or results that are consistent with the internal methods.
[[StringData]]
internal slotThe behavior of String
, e.g. new String("whatever")
, is described in terms that include a [[StringData]]
internal slot that represents the value (whatever
in this case). The internal slot isn't directly accessible to user code, but String.prototype.toString()
(e.g. (new String("whatever")).toString()
) is defined in terms of a thisStringValue()
abstract operation, which is described in terms of returning the value of [[StringData]]
. So in other words, String.prototype.toString()
is public API that is essentially a getter that exposes [[StringData]]
.
[[OwnPropertyKeys]]
internal methodThe behavior of Object.keys() is described in terms that include calling the [[OwnPropertyKeys]]
internal method. Note that different kinds of objects, such as ordinary objects (e.g. Object) and exotic objects (e.g. String) may have different definitions of [[OwnPropertyKeys]]
. When [[OwnPropertyKeys]]
is "called" in the spec, that refers to the definition for the applicable type. There are also some invariant characteristics that apply to its definition for any object type.